renv paths - empty libraries when sharing R project which uses renv package - r

I'm using the 'renv' R package in an RStudio project to control/lock the package versions used by my script. The libraries sit in the project directory under ... renv\library\R-4.1\x86_64-w64-mingw32. I'm using R version 4.1.3 and renv 0.15.5. When this directory is copied to a colleague's machine (using memory stick) the libraries in the directory mentioned above are blank. I'm assuming these libraries are just pointers to where R saves packages (e.g. "C:/Program Files/R/R-4.1.3/library") and my colleague doesn't have these packages on their machine.
Is there a way to include the packages themselves when sharing the RStudio Project directory?

By default, packages within the renv project directory are symlinked from a global cache location. If you want to ensure packages are instead stored locally in the project library, you can use renv::isolate().
See https://rstudio.github.io/renv/reference/isolate.html for more details.

Related

How can I install all my project library packages in my system library?

I am using the r package renv. I have somehow managed to delete most of my system library packages. Fortunately, one of my project renv.lock files contains nearly all my packages.
What I want to do is to install all the packages in the renv.lock file in my system library.

How to import the installed packages for `renv` by default

I want to test the potential function of the collective maintenance of the R scripts across individuals. I try to work on Rstudio project together with the Could software eg. Dropbox and the version control (eg. Git), so we can have all the records of all the updates from different maintainers. Therefore, I try to test the new released R package renv.
On my Mac OS, my newly installed packages are available in the 1st directory as I listed below.
.libPaths()
## [1] "/Library/Frameworks/R.framework/Versions/library"
## [2] "/Library/Frameworks/R.framework/Versions/3.6/Resources/library"
However when I start the renv with the renv::init(). It only has the basic packages available. How can I move these installed packages into the global cache directly without the need to reinstall these pacakges?
You can simply call renv::install() (or renv::restore()) and renv will find packages already installed in the cache. It's possible because all the projects using renv share the global package cache, therefore, the project libraries are composed by symlinks associated to the global package cache.
In case that renv global package cache and the project library are installed in different disk volumes, renv will copy the package from the cache into the project library, instead of using a symlink.
In macOS, the default location of renv global packages caches is: ~/Library/Application Support/renv.
All the information was extracted from the following link: https://cran.r-project.org/web/packages/renv/vignettes/renv.html.
I hope it helps you. Good luck!

How do i keep source files when using R's devtools library function 'install'

I am trying to build an R package (DESeq2) from source so that I can debug it. I've installed all the dependencies required and I'm following Hillary Parker's instructions for creating R packages. I'm running this on CentOS 6.6 using R-3.4.2.
I run :
library("devtools")
install("DESeq2", keep_source=TRUE)
It installs it in the directory with all my other R libraries. When I look at the installed DESeq2 library it is missing all the DESeq2/R/*.R and DESeq2/src/*.cpp files.
QUESTION : Where are these files and why didn't they get installed? This does not seem like the expected behavior.
R uses binary database format for installed packages to pack the objects into a database-alike file format for efficiency reasons (lazy loading). These database files (*.rdb and *.rdx) are stored in the R sub folder of the package installation path (see ?lazyLoad).
Even if
you are looking at the right place to find the installed package (use .libPaths() in R to find the installation folder)
and you have installed the package with the source code (like you did or
via install.packages("a_CRAN_package", INSTALL_opts = "--with-keep.source"))
you will not find R files in R folder there.
You can verify that the source code is available by picking one function name from the package and print it on the console. If you can see the source code (with comments) the package sources (R files) are available:
print(DeSeq2::any_function)
To make the source code available for debugging and stack traces you can set the option keep.source.pkgs = TRUE (see ?options) in your .Rprofile file or via an environment variable:
keep.source.pkgs:
As for keep.source, used only when packages are
installed. Defaults to FALSE unless the environment variable
R_KEEP_PKG_SOURCE is set to yes.
Note: The source code is available then only for newly installed and updated packages (not for already installed packages!).
For more details see: https://yetanothermathprogrammingconsultant.blogspot.de/2016/02/r-lazy-load-db-files.html

src-{i386,x64} folders in R package

While installing an R package containing Rcpp code using the devtools::install() command, two new folders - src-i386 and src-x64 were created. This would not happen earlier. Also this happens on a Windows system only. I'm guessing this is a result of a new feature added in the devtools package.
Question: Should these folders be included in the git repository?
No.
Only src/ should be included within a git repository.
The src-i386 and src-x64 folders are artifacts left over from a multi-architecture build on Windows (e.g. x86 and x64). These folders are the result of R's the command line install using R CMD INSTALL ..., which is wrapped by devtools.

r packrat unbundle not recreating libraries

I am having trouble understanding what I am doing wrong when deploy a shiny application on shiny server using packrat to managing the libraries.
I create project test-deploy in RStudio, then initiate packrat with.
packrat::init()
As I work I am installing packages (dplyr, ggplot2, etc). These are stored in /test-deploy/packrat/lib/[OS]/[R Version] . All good so far.
Done working ready to deploy.
packrat::bundle()
Creates a tar file which is unbundled to shiny server with
packrat::unbundle("/test-deploy/packrat/bundles/test-deploy-2017-07-14.tar.gz", "/srv/shiny-server/")
I go to that app on shiny-server and make turn packrat on
packrat::on()
Now I check what packages are installed other than the base packages with
ip = as.data.frame(installed.packages()[,c(1,3:4)])
ip = ip[is.na(ip$Priority),1:2,drop=FALSE]
ip
Output
Package Version
packrat packrat 0.4.8-1
The other packages which I can see in the development version are not there? What am I doing wrong ?
I forgot to include
packrat::snapshot()
before
packrat::bundle()

Resources