All Collections
User Manual
Advanced environment configuration
Installing R packages through postInstall
Installing R packages through postInstall

A few notes on flags and parameters you may need to add

Updated over a week ago

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);

  • add parameters to devtools::install_github() , such as subdir= .

This help article includes some code snippets and an example that may help.

Set helpful options

At the top of your script, put the following:

echo "options(repos ='https://cran.rstudio.com/', \
  unzip = 'internal', \
  download.file.method ='libcurl', \
  Ncpus = parallel::detectCores() )" >> /etc/R/Rprofile.site

This will address a variety of installation issues you'd have otherwise (likely) encountered. (You don't need to use the official CRAN mirror.)

Set the tar command

In your Rscript  command(s), include Sys.setenv(TAR = '/bin/tar'); .

Write everything as one string of commands

 To avoid setting the same parameters multiple times, string R commands together with the delimiting character ;  a \  character will  allow multi-line commands. For instance, your final script might look like:


#!/usr/bin/env bash
set -ex
echo "options(repos ='https://cran.rstudio.com/', \
  unzip = 'internal', \
  download.file.method ='libcurl', \
  Ncpus = parallel::detectCores() )" >> /etc/R/Rprofile.site

Rscript -e "Sys.setenv(TAR = '/bin/tar'); \
   install.packages('devtools'); \
   devtools::install_version('dplyr'); \
   devtools::install_version('emmeans'); \
   devtools::install_version('furrr')"

This script sets the necessary options and then installs packages all at once. 

Further questions or issues?

Please write to us at support@codeocean.com or via live chat, and we'll be happy to assist.

Did this answer your question?