Install R packages on an offline server

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

  1. Install the same R version on your machine as the offline machine’s
    1. Windows will require Rtools to compile from source
  2. Create and open an R session in a new directory
  3. Install packages needed
    1. 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.
    2. Pro tip: package pak allows simultaneous download so will probably speed up the installation
  4. install.packages(‘renv’)
    1. Renv is a R package management tool
  5. Create a script in the directory, and load the libraries that you need in that script using library(package)
    1. so that renv knows that you need these packages in the directory
  6. renv::init()
  7. renv::isolate()
  8. 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
Avatar
Tim

Personalizing medicine

Related

comments powered by Disqus