All Collections
Tips and Tricks
New and additional languages, toolboxes and compilers
Installing R in a non-R environment, or updating to the most recent version
Installing R in a non-R environment, or updating to the most recent version

How to add a recent R version to any environment

Shahar Zaks avatar
Written by Shahar Zaks
Updated over a week ago

Code Ocean's starter environments use Ubuntu Linux as their operating system. Ubuntu's package manager, APT/apt-get (which can be operated using Code Ocean's user-friendly environment editor) provides as set of packages to install different subsets of R, the primary one being r-base.

While Code Ocean's environments are based on a recent version of Ubuntu (18.04 code name "Bionic Beaver" or just "Bionic" – you'll see why this is important in a minute), the version of R it includes, 3.4.4, is about two years old (!). Luckily, there's a way to get newer versions of R to install on Code Ocean:

  1.  In the environment editor, click the gear icon next to apt-get. This will open the apt-get configuration window.

  2. In "additional sources", copy and paste deb bionic-cran35/ (for R 3.6) or deb bionic-cran40/ (for R 4.1). This tells apt-get to search for packages on the R project's own repository.

  3. In "GPG Keys", copy and paste E298A3A825C0D65DFD57CBB651716619E084DAB9. This is a piece of information provided by the R project to guarantee the authenticity of the repository.

You should end up with something like this:

After you save your changes and get back to the environment editor, the last and crucial step is to add r-base as an apt-get dependency. (You'll notice the various R installer options will show up automatically, which you can immediately add packages to.)

Did this answer your question?