In general, don't do this. Most of the time, Code Ocean's available package managers will be simple and quick to use.

You may need to use the postInstall script, however, if you: 

  • need to install packages in a very specific order;
  • build packages that are no longer on CRAN (installing them from archives);
  • use bioconductor packages but don't have either the bioconductor installer or Conda (with the Conda channels r  and bioconductor ). 

If you go this route, you may encounter some bugs and issues. This article covers a few for R in particular. If something isn't covered or you are still having issues, please write to us at support@codeocean.com or via live chat. 

Add a CRAN mirror 

 R won't automatically know which CRAN mirror to use. Without one, you'll see the following error message:

Error in contrib.url(repos, type) : 
  trying to use CRAN without setting a mirror
Calls: install.packages -> grep -> contrib.url
Execution halted

 You should set this explicitly:

Rscript -e "install.packages(c('devtools', 'ggplot2'), repos = 'https://cloud.r-project.org/')"

Set unzip and untar options

If you are installing packages from devtools::install_github()  or BiocManager::install() , you may receive ambiguous error messages, such as:

Installation failed: error in running command

These typically occur when R is not finding the necessary internal tools to unpack files. To remedy this, write a script that installs packages after first setting the following options:

options(unzip = 'internal'); \
  Sys.setenv(TAR = '/bin/tar'); \

This issue on the conda-forge GitHub page for devtools has more information, as does this commit on the remotes package's GitHub page.

Write everything as one string of commands

 To avoid setting the same parameters multiple times, you should string R commands together with the delimiting character ;  a \  character will also allow multi-line commands. For instance, this capsule has: 

 Rscript -e "install.packages('devtools', repos = 'https://cloud.r-project.org/'); \
  library(devtools); \
  options(unzip = 'internal', repos = 'http://cran.cnr.berkeley.edu'); \
  Sys.setenv(TAR = '/bin/tar'); \
  devtools::install_github(repo = 'kassambara/easyGgplot2@v1.0.0'); \
  devtools::install_version('BiocManager', version = '1.30.3'); \
  devtools::install_version('metafor', version = '2.0-0'); \
  devtools::install_version('rasterVis', version = '0.45'); \
  BiocManager::install('MetaGxOvarian', version = '3.8'); \
  BiocManager::install('MetaGxBreast', version = '3.8'); \
  BiocManager::install('MetaGxPancreas', version = '3.8')"

All of the the above are passed to the command Rscript -e  and are executed sequentially, so the repo, unzip, and untar options apply to every package.

Did this answer your question?