Installing an older version of R in a conda environment

This will walk you through installed an old version (3.4.1) of R inside a conda environment. We assume you have anaconda installed and are somewhat familiar with it’s commands.

Installing R

First we create a new environment:

> conda create -n myRenv3_4 anaconda

and then switch to the new environment with:

> source activate myRenv3_4

To confirm we have this running properly we can ask where the pip command will run from (hopefully it is tied to a location inside our environment):

> which pip

Note that R is not installed by default inside the environment:

> which R

Next we search for the R version we want to install. Because conda’s search will match any packages that contain our search term as a substring (in our case the letter “r”) we search instead for “r-base”:

> conda search r-base
Fetching package metadata .........
r-base                       3.1.2                         0  defaults        
                             3.4.1                         0  defaults        
                             3.4.1                         1  defaults        
                             3.4.2                haf99962_0  defaults        
                             3.4.3                h290ecf8_0  defaults        
                             3.4.3                h290ecf8_1  defaults        
                             3.4.3                h1e0a451_2  defaults        
                             3.5.0                h1c2f66e_1  defaults        
                             3.5.0                h1e0a451_1  defaults        
                             3.5.1                h1e0a451_2  defaults        

Now that we’ve confirmed the package/version we want is available we R v3.4.1 with the following:

> conda install -c conda-forge r=3.4.1

One can also try installed with -c r instead of conda-forge but I’ve found that not all versions are available via r.

To confirm that this installed properly (you might have to source deactivate and source activate to get :

> which R

When we open R we should see the following:

> R
R version 3.4.1 (2017-06-30) -- "Single Candle"

but on some installs I’ve seen the following error:

> R
/anaconda/envs/myRenv3_4/lib/R/bin/exec/R: symbol lookup error: /anaconda/envs/myRenv3_4/lib/R/bin/exec/../../lib/../../ undefined symbol: PC

This can be fixed with an update to the readline package (see this ticket for more info):

> conda install -c conda-forge readline=6.2

Next, the Native R kernel for Jupyter is installed with:

> conda install -c r r-irkernel
Incompatible packages with our current R version

Some packages won’t be available for v3.4.1, for example the effects package:

> install.packages("effects")
Warning message:
package ‘effects’ is not available (for R version 3.4.1)

To get around this we will install oldr for installing packages compatible with R v3.4.

First we install the R package devtools:

> conda install -c r r-devtools

and then inside R we install oldr:

> require(devtools)
> devtools::install_github("duckmayr/oldr")

This often results in the following error:

Downloading GitHub repo duckmayr/oldr@master
from URL
Installation failed: error in running command

which can be fixed by (see this ticket):

> options(unzip = "internal")
> devtools::install_github("duckmayr/oldr")
> oldr::install.compatible.packages("effects", "3.4.1", "/anaconda/envs/myRenv3_4/lib/R/library")

Here we also have to specify the R version we are running and the location of the install.