Deploying projects with renv in offline environment - r

What is the correct procedure to deploy packages using renv to an offline machine?
We have an internal CRAN-like repository, which is configured via options(repos = list(cran = "http://our.repo.url")) on both the development machine and the deployment machine. It is specified in renv.lock. The renv package itself is installed on both machines, and both are the same version (1.14).
After deployment, after starting R in the project directory, it hangs for a while, and returns an error:
# Bootstrapping renv 0.14.0--------
Warning: unable to access index for repository https://cloud.r-project.org/src/contrib/:
cannot open URL 'https://cloud.r-project.org/src/contrib/PACKAGES'
* Downloading renv 0.14.0 ... FAILED
How do I tell renv to either copy itself from the system library, or install from the internal repository?
Copying from the system library would be of course the preferred course of action, to save time compiling.

You might want to file an issue at https://github.com/rstudio/renv/issues since I think renv doesn't currently support loading the renv package from a non-project library path via the autoloader.
That said, you should be able to move forward by disabling the renv auto-loader. Before launching R, you can set the environment variable:
RENV_ACTIVATE_PROJECT = FALSE
Then, when R is started, the renv auto-loader (run via source("renv/activate.R") in the project .Rprofile) will be disabled. You can then later load renv from whichever library path is appropriate, and call renv::load() to manually load a particular project.
(The other alternative to setting that environment variable is simply removing the renv auto-loader from the project .Rprofile.)

Related

Using renv: where should renv itself be installed?

I am getting started with collaborating with team members on R projects using renv. While I can (mostly) get it to work, I am a bit confused about whether and where to install renv itself. According to the documented workflow I basically need renv installed before I start a new project with renv.
However, when I do not have renv installed, and clone a repo that uses renv, it seems to install (bootstrap?) itself. But it does this within the local renv environment.
I have a couple of questions regarding this:
Do you recommend to have renv installed "outside" the renv virtual environment?
How do you deal with differences in versions of renv itself between what is e.g. installed on my machine and present in a repo that I clone, and which renv I would like to replicate? I ran into problems with this one, could not replicate a renv from a cloned repo with a different renv version.
On a more conceptual level: why is renv itself part of the virtual environment it creates? That's not the case for the python virtual environment managers I know.
Do you recommend to have renv installed "outside" the renv virtual environment?
We do. In fact, this is necessary if you want to initialize an renv project in the first place, since this is done by calling renv::init() -- and so the regular renv initialization workflow expects renv to be installed into the user library.
How do you deal with differences in versions of renv itself between what is e.g. installed on my machine and present in a repo that I clone, and which renv I would like to replicate? I ran into problems with this one, could not replicate a renv from a cloned repo with a different renv version.
Since renv is just an R package, you can install or upgrade (or downgrade) the version of renv used within a project as required, without affecting other projects. For example, installing the latest version from CRAN can be done with a plain install.packages("renv").
When working within an renv project, the version of renv installed in that project is normally the copy that is used -- so at this point, it should no longer matter what version of renv is installed in the user library.
On a more conceptual level: why is renv itself part of the virtual environment it creates? That's not the case for the python virtual environment managers I know.
This is done primarily to ensure existing renv projects can continue to function even if an update to renv happened to break some existing workflows. (We endeavor to make sure that will never happen, but want to make sure users have an escape hatch in case it does.)
However, when I do not have renv installed, and clone a repo that uses renv, it seems to install (bootstrap?) itself. But it does this within the local renv environment.
The "bootstrap" behavior here is done to help streamline the collaborative workflow. Rather than requiring users explicitly install renv before opening an renv project, renv knows enough to bootstrap itself in an existing project so that new users can get up and running quickly. (In addition, the bootstrapper script also tries to ensure that the version of renv that project was configured to use is installed.)

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

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.

deployment on shinyapps.io failing

Hi I'm trying to deploy an app on the server, however, I get the following errors
* May be unable to deploy package dependency "rClr" could not
determine a repository URL for the source CRAN.
* May be unable to deploy package dependency "tlf" could not determine
a repository URL for the source CRAN.
Unable to determine the source location for some packages. Packages
should be installed from a package repository like CRAN or a version
control system. Check that options(repos) refers to a package
repository containing the needed package versions.
The backbone packages can not be installed from Cran and have to be done manually, hence the errors. How can this be fixed in order to deploy the app on the server?
Thanks for all help

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!

R: installing package to a different location from R base

I am accessing R-3.4 from a location on a shared drive. IT have configured it such that, when I install a package, it will default to installing it on my local drive. In many cases, it succeeds with a warning, but a few packages are failing, saying they can't access other libraries/packages.
The location on the shared drive is available in .libpaths(), and when I specifically install to this location using install.packages("package_name", lib = .libpaths()[2]), these packages install successfully.
Unfortunately, IT have told me I'm not allowed to install to the shared drive. So: is there a way that I can install a package to my local drive, but tell install.packages() to refer to the shared drive for any dependencies?
(This problem has so far arisen with installing arules, RGoogleAnalytics, and googleAnalyticsR, but I suspect they won't be the only ones.)

Resources