Benefits of using renv
over R CMD INSTALL
:
- no manual downloading and installing of packages
- no need to worry about R package dependencies (to other packages)
- other goodies of
renv
: e.g. reproducible environment
Prerequisite:
- Access to a machine with internet connections in the same operating system as the server’s operating system.
- If using RStudio on Windows, you need a Windows machine
- If using R in Linux, need a Linux machine (Farm server works too)
- Virtual machine and WSL should probably work
Steps
- Install the same R version on your machine as the offline machine’s
- Windows will require Rtools to compile from source
- Create and open an R session in a new directory
- Install packages needed
- When installing some packages in an old version of R (e.g. 3.5), there could be cases where installation from source will be newer than installation from binary (because CRAN did not build binary for an old version of R), and these new versions will be dependencies for other packages. Thus, if you do not install from source, installation of other packages can return error.
- Pro tip: package
pak
allows simultaneous download so will probably speed up the installation
install.packages(‘renv’)
- Renv is a R package management tool
- Create a script in the directory, and load the libraries that you need in that script using library(package)
- so that renv knows that you need these packages in the directory
renv::init()
renv::isolate()
- Now move the directory to the offline server (probably zip it first). When you open an R session in the directory on the server, all packages should now be available to you