R develop packages without installing every time - r

I am developing an R package, but every time I make some modifications
I have to use R CMD INSTALL to install it and see if the new version
is working.
I would like to know if there is some easier way to develop a package in R.
Specifically I would like to be able to develop the package without having
to install it every time I want to test it.
If you are familiar with Python and setuptools, I would like to achieve the
same effect you get using
python setup.py develop.

Install devtools, then all you need to do is:
require(devtools)
load_all("/wherever/your/package/is")
It reloads all the changed code in .R files, recompiles, links, loads C code and so on.
devtools will also compile your documentation, and run checks.
Nothing else comes close for package development.

Related

Running R from Excel using specific old R packages

First time question asker.
I created an Excel/R tool that uses:
Excel VBA to create a CSV file with data for R,
Launch R using a Windows Shell,
Detects when R is finished running and then
Imports the results in a CSV file created by the R script.
Unfortunately, the R code does not work as programed with some package versions created after 3/1/2020, which creates problems for new users because they cannot just install the current package versions or users who want to use conflicting versions for other projects.
I have a solution for users who do not require newer versions of R for their other work; writing a script that installs all the packages and their dependents using the “versions” package. However, I think this approach will constrain users who want to use newer versions of R. **Is this a correct assumption? **
I thought the {checkpoint} package might offer a good solution. I can get it to run in well in RStudio by creating a RStudio project (where I ran the {checkpoint} package to install the 3/1/2020 versions of my packages). However, I have not found a way to run the R script from the Windows Shell. The R script does not seem to be able to access the packages installed in the RStudio project using {checkpoint}. Does anyone have ideas of how I can have Excel VBA launch the start of the R script in a way that it can assess the packages installed in the RStudio project by {checkpoint}? Perhaps there is a Windows Shell call for RStudio similar to the one I use now for R?
Here is the Windows Shell code I currently use for R in case it helps. It works with the versions approach but not the {checkpoint} approach.
rExeCall = "C:\Program Files\R\R-3.6.2\bin\Rscript.exe"
rExeOptns = " --no-environ --no-init-file --no-restore --verbose "
rscrpt=”Tool.R”
Shell (rExeCall & rExeOptns & rscrpt)
Thank you in advance for your help!
I had hoped that my current R shell code would work when I used {checkpoint} to install the correct versions of the packages in an RStudio project.
I tried specifying the .libPaths to the file location for the RStudio projection (per Running R script from PHP in VSCode not recognizing R packages) without success.

RStudio and devtools do not install static vignettes

I created an R package for an introductory course in remote sensing with R (github link) and want to provide the handouts as as static PDF vignettes (copy protected) as described here. With the standard Linux commandline "R CMD build FEglobaleOekologie && R CMD INSTALL FEglobaleOekologie_0.0.1.tar.gz" everything works fine. However, when I install it from within my RStudio project or under MS Windows with devtools::install_github" there are no vignettes. The later one is the target platform, where I would like to have them.
Sadly I could not find any thread, that solves my problem. Can anyone tell what's going wrong here or what I am doing wrong?
I've run into problems like this, too. I've found that build doesn't always build my vignettes (that generally happens with using build in the RStudio menu, since I believe that doesn't include the vignettes by default ). You might want to try also running build_vignettes() before uploading to GitHub; and when installing from GitHub, explicitly including build_vignettes = TRUE in the install_github function. Otherwise, you may have a path issue for the installed package.

Install R packages on the fly

Whenever I want to run a complex application in R that needs many packages and libraries, I have to install one by one all the dependencies and then re run again to see the next dependency. I am having the same problem with running a shinydashboard app. I wonder if there is a way the first time I am about to execute an R script, at the same time to install on the fly all the dependencies this script needs. I am running an R server on windows. Thanks!
Perhaps you want to use pacman
library(pacman)
p_load(dplyr, reshape2) # install if needed, then load

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

R install packages from Shell

I am trying to implement a reducer for Hadoop Streaming using R. However, I need to figure out a way to access certain libraries that are not built in R, dplyr..etc. Based on my research seems like there are two approaches:
(1) In the reducer code, install the required libraries to a temporary folder and they will be disposed when the session is done, like this:
.libPaths(c(.libPaths(), temp <- tempdir()))
install.packages("dplyr", lib=temp, repos='http://cran.us.r-project.org')
library(dplyr)
...
However, this approach will have a dramatic overhead depending on how many libraries you are trying to install. So most of the time will be wasted on installing libraries(sophisticated libraries like dplyr has tons of dependencies which will take minutes to install on a vanilla R session).
So sounds like I need to install it before hand, which leads us to approach2.
(2) My cluster is fairly big. And I have to use some tool like Ansible to make it work. So I prefer to have one Linux shell command to install the library. I have seen R CMD INSTALL... before, however, it feels like will only install packages from source file instead of doing install.packages() in R console, figure out the mirror, pull the source file, install it in one command.
Can anyone show me how to use one command line in shell to non-interactively install a R package?
(sorry for this much background knowledge, if anyone thinks I am not even following the right phylosophy, feel free to leave in the comment how this whole cluster R package should be managed.)
tl;dr
Rscript -e 'install.packages("drat", repos="https://cloud.r-project.org")'
You mentioned you are trying to install dplyr into custom lib location on your disk. Be aware that dplyr package does not support that. You can read more in dplyr#4641.
Moreover if you are installing private package published in internal CRAN-like repository (created by drat or tools::write_PACKAGES), you can easily combine repos argument and resolve dependencies from CRAN automatically.
Rscript -e 'install.packages("priv.pkg", repos=c("cran.priv","https://cloud.r-project.org"))'
This is very handy feature of R repositories, although for production use I would recommend to cache packages from CRAN locally, and use those, so you will never be surprised by a breaking changes in your dependencies. For quality information about handling R in production I suggest to look into talk by Wit Jakuczun at WhyR2019 How to make R great for machine learning in (not only) Enterprise: slides, video.
You may find littler useful. It is a command-line front-end / variant of R (which uses the R-embedding interface).
I use the install.r script all the time to install package from the shell. There is a second variant with more command-line argument parsing but it has an added dependency.

Resources