Set up conda environment for R package not on CRAN, installs to wrong location

My goal is to use this package (https://github.com/tiagodc/TreeLS) but it was deprecated from CRAN (https://cran.r-project.org/web/packages/TreeLS/index.html). It requires an older version of R yet its dependencies such as the raster package require R 3.5 or up. I considered two approaches.

  1. using R studio and changing the global options to an older version of R, but I frequently use many geospatial packages and since this package has older dependencies I didn't want to install older versions of packages I use all the time.
  2. Create a virtual environment in Mini Conda 3 dedicated to use for this package. I choose this option because it would be self contained.

Here is the workflow so far.

conda search -c r r
conda create -n newR351 -c conda-forge r-base=3.5.1 -y
conda install -c r rtools -y

Successfully creates a conda environment called newR351 and installs r tools to that environment folder within mini conda 3.

Location of conda environment with R 3.5.1 install

C:\Users\me\Miniconda3\envs\newR351

When I try to install devtools so I can remote install TreeLS from github I get a warning with zero exit status. The devtools package installs, but it installed to my appdata folder and not my mini conda environment.

conda install -c r devtools -y

The downloaded source packages are in
    'C:\Users\me\AppData\Local\Temp\RtmpYByvp8\downloaded_packages'

How can I access devtools on my conda environment newR351? Do I need to build a cran skeleton? When I activate R in this environment and try to load the devtools library I get this.

(newR351) C:\Users\me>R
R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

...

>library(devtools)
Error in library(devtools) : there is no package called 'devtools'

What are best practices for creating an environment specific for an older R package? Anyone else use TreeLS?


Solution 1:

First, the devtools isn't showing up because R packages in Conda repositories are conventionally prefixed with "r-", so installing conda install r-devtools should do the trick. However, I don't think Conda is the best strategy here.

Below R version 3.6, the Conda package coverage for R packages is rather poor. Also, installing non-Conda packages that require compilation into a Conda R environment is a pain and generally doesn't work out-of-the-box in my experience. Plus, not only does the TreeLS require compilation, but it has dependencies that are not Conda packages which require compilation. I would avoid this.

Option 1 is feasible. R allows multiple installations, and with manipulating environment variables (I think RSTUDIO_WHICH_R, R_LIBS are the pertinent ones) one can switch between them.

However, were this my situation, I'd spin up a docker container, probably rocker/rstudio:3.5 and use that for this project. Since the underlying image is Linux, it'll take awhile to compile, but you can version it at that point and then always have that available to spin up. This avoids having to muck around with any system settings and should be mostly straight-forward installing.