Can a user of a GitHub R package avoid first installing and loading devtools - r

Suppose I have an R package on GitHub. Is there any way, I can have an RStudio user of my package avoid first running:
install.packages("devtools")
library(devtools)
and just directly use:
install_github("My-Github-username/My-package-name")
library(My-package-name)
Can I for example make any changes to my R package such that my package automatically does install.packages("devtools") and library(devtools) for the user?

You somehow need to get your user to install and build the package locally to use it. The package can't install itself. Think of the package as a collection of code. You somehow need to get the code from GitHub to your user's computer.
If using devtools is not an option, you could have them do this manually (by, say, downloading the .tar.gz from GitHub) and then build the package themselves, using R CMD build and R CMD install such. There are some nice explanations out there on how to go about doing this. Using devtools::install_github() is a convenient, easy function that takes care of all of those steps for you.
(The exception to my statement "The package can't install itself" is that you can use devtools to install devtools.)

Related

Difficulty installing a package in R linux, dalton_rqi

Downloaded package from below URL.
Attempted to install using below command; response shown.
library(dalton.rqi,lib.loc='/home/X/Desktop/')
Error: package ‘dalton.rqi’ was built before R 3.0.0: please re-install it
https://my.clevelandclinic.org/departments/anesthesiology/depts/outcomes-research/risk-quantification
It appears this is a compiled package that maybe I don't have the source for? Is there a way to force install of the package? I'm unable to install using Rstudio GUI in its current form as a zip. Tried repackaging to tar.gz has Rstudio was looking for and also had a non-zero exit status error.
Any ideas?
I'm afraid this can't be achieved directly. The error message says it well: to use a package in R it needs to be built on an R version matching yours.
I can suggest two ways to move forward:
Contact the authors, ask for the R sources (it is somewhat surprising they did not make them available in the first place), and build the package yourself.
Downgrade your R version as far back as needed to match the one this pre-built package used.

Installing local binary packages using R CMD INSTALL on a Mac

I came across a package that is not available on CRAN. I tried to install the package using:
Packages & Data > Package Installer > Local Binary Package > At User
Level > [FileName.tgz] > Install...
This didn't work and I am now trying to use the R CMD INSTALL command. However, it seems I need to run that command in the command line interface but I cannot get it to install properly.
The package I'm trying to install is called gEcon. It can be found here. In particular, I am getting the following error message after "installing" the package:
Error: package or namespace load failed for ‘gEcon’:
package ‘gEcon’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version
I assume it's the way I'm installing it.
Thanks in advance.
You're going to need to install Xcode apparently, because you've got to install this from source per these directions:
Now, you've gotta update R to the latest stable release, or if you prefer you can find the exact minimum newest version needed for gEcon.
After upgrading R you can complete the installation from source.
Original answer to original question:
Two things:
To access the command line and use R CMD on an Apple computer, please use the terminal.app app. Please see this for more details.
An easier and probably better approach is to install your package from the author's Github (or BitBucket, etc) repository using devtools::install_github or just use devtools::install on the downloaded source project.

Testing installing a newly built R package and its dependencies

I have just created a Rpackage in RStudio, built it and installed into the same R version. Basically I have pressed the "Build and reload the package (Ctrl + Shift + B)" button. By this method I get the package installed in the same R version, so that library(mypackage) works directly and I can use my own package in another RSession.
However, I would like to pass the package for others to be used and test that all package dependencies work as desired. Therefore, I have invoked "Build binary package" in order to have package mypackage_{version_number}.zip.
What is the preferred way to test the installing of a newly created binary package and, especially, its dependencies?
My primary environment has all dependencies installed, therefore, Imports: clausus in DEPENDENCIES file seem to have no effect. The installing of all necessary dependencies is exactly what I would like to test.
I found the idea of trying to install the package into another R version. However, in that case I could test the dependencies only once, because all the dependencies (hopefully) get installed to that R version when installing the package and its dependencies first time.
If Travis is not an option, you could test your package using win builder (http://win-builder.r-project.org/) through devtools::build_win().
Make sure to add the maintainer role in authors in the DESCRIPTION of your package, because win builder will send an email once the tests are completed.

Reload updated package in R

I used to develop some package for R. So, this is an iterative process where I need to check the working of the package in between by installing it via rstudio, and then again adding some necessary functionalities. So, I used the following process:
create a R package
install it via command prompt: R CMD install <{package_name}>
load the package in rstudio as, library(package_name)
Check the necessary functionality
detach package in rstudio using, detach(package:{package_name})
remove package via command prompt as: R CMD remove <{package_name}>
add/update package
repeat steps 2 - 7,until package is fully developed.
Now the problem is that everytime I close rstudio after step 5, otherwise updated package after installation is not reflected in R.
So, How can I avoid to close rstdio everytime; and always get updated copy of installed package. In other words, I don't want to close rstudio everytime. I have found that detach( ) is not effective.
Note: I use rstudio only for checking the functionality of package. I check,build for building packages on command prompt using R CMD check/build commands
RStudio has functionality for building packages that I does what I think you have described.
Basically, use 'new project' and select the R-package option or just open an old project using the '.Rproj' file
Then use the build and reload each time you make a change to the package
and want to reload the package in (see pic).
Seems to work OK for me.
See link for more details:
https://support.rstudio.com/hc/en-us/articles/200486488-Developing-Packages-with-RStudio

Installing Packages in R - mgarch

im trying to install mgarch package from Github. I downloaded the zip file: mgarch_0.00-1.tar.gz
I tried this procedure:
install.packages('package.zip', lib='destination_directory',repos = NULL)
as said here Manually Downloading and Installing Packages in R
But didnt work
Another procedure was: How to install development version of R packages github repository
As suggested at this link i had to install devtools from Hadley.
install.packages("devtools")
library(devtools)
dev_mode(on=T)
install_github("ggplot2")
I did, and nothing happened.
As a begginer im really lost. Just want something to clear my way, because i need to run an BEKK GARCH Model.
try this
library(devtools)
install_github("vst/mgarch")
library(mgarch)
installs this package https://github.com/vst/mgarch
is that the one you want?
the syntax for install_github is (usually) install_github("username/repository") this is rather poorly documented in the ?install_github documentation

Resources