How to Install 2 Different R Versions on Debian

How to install 2 different R versions on Debian?

As I mentioned in comments, this is theoretically possible just like some package families (Emacs, PostgreSQL, ...) allow multiple concurrent versions.

I cannot offer that right now as we use /usr/{share,lib}/R which conflicts. If I were to make that /usr/{share,lib}/R-$version and then use dpkg-alternatives to flip to a default preferred one, we could possibly do it. The problem is the transition. This feature is used by a minority of user, getting to it may introduce bugs for a majority til this is stable. Plus, I do not have the spare time (but if someone else wants to do it, please do so).

In the meantime, you can

  1. possibly use an advanced feature of dpkg and unpack to a local directory rather the default below / -- so /opt/R/oldversions/2.12.1 should be possible. R could even run, you need to redefine $RHOME accordingly.

  2. just build local variants into /usr/local if you really must

  3. if a particular CRAN / non-CRAN package claims to need a particular version of R, fix the damn package already! ;-)

Finally, this is a topic for r-sig-debian as eg the CRAN maintainer Michael and Johannes won't read this thread here.

Installing multiple versions of R

Yes, this is pretty easy as Josh Ulrich's comment already says.

People usually have this question regarding r-devel installation alongside the basic R you will get from your distro. I use a simple shell script to build / update R-devel, and two matching ones to run R-devel and Rscript-devel. I can't recall if I blogged about it, but folks seem to point to an this older post on the r-sig-debian list which contains it. Here is a nice post by Michael detailing the same process.

And by creating new subdirectories, you can add as many R version as you want. You should keep the local builds in /usr/local, though, and could create softlinks for the binaries in /usr/local/bin. The script R itself will have R_HOME_DIR hard-coded and "just work".

Fancier approaches involve virtualization, and on Linux your best bet is docker which I am playing with now, and which I hope to detail at some point for this very purpose of testing R packages against multiple compilers etc.

How to install a specific R version in ubuntu

You will need to build from source. Using this post as guideline: https://unix.stackexchange.com/questions/173/how-to-compile-and-install-programs-from-source

  1. Download the tar.gz for specific version
  2. Extract using tar zxvf myapp.tar.gz
  3. cd into the directory by step 2
  4. run ./configure && make && sudo make install

R versions and associated libraries

Based on the comments above and testing on my machine R seems to use the libraries associated with whatever R version is being used in the following directories (e.g. c:/Users/user1/Documents/R/win-library/4.1; c:/Program Files/R/R-4.1.2/library). As @r2evans has stated above this can be changed using the .libPaths() function.

How do different versions of R manage to seemingly automatically download different appropriate package versions from CRAN?

This isn't an answer, but it is too long for a comment. If I understood correctly, an user can tell you that he wants the package X and you have to provide it to him. I guess that you can download somewhere the correct version and transfer the package to the user's machine.

This seems hard to do in general, but maybe doable. However, it requires a little cooperation from the user.

As already said in the comments, the package archive exists and has all the old versions of each package. Keep in mind that the following line:

installed.packages()

gives you all the packages installed on a machine. I don't think that this could be too much to ask to the user.

I'd proceed as follow.

  • Get to the archive page of the desired package.
  • Download the newest package source, unfold it and check the DESCRIPTION file.
  • From it, see if the package is compatible with the user's R version. If not, download the second-new and so on.
  • Check the fields Depends and Import of the DESCRIPTION file, to meet the dependencies and see if they are installed by examining the object returned by installed.packages() from the user's machine.
  • If a package is missing, go recursively to meet all the dependencies.
  • If you are done, now you need to compile each downloaded package (since archives seems to have just the source code, you need to compile it to distribute it to the user's machine).

All the above steps can be done by writing a simple function. It might be boresom to deal with all the exceptions, but I guess that it shouldn't be so hard to do the above in R (or in other programming languages, depending on your expertise).



Related Topics



Leave a reply



Submit