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
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.just build local variants into
/usr/local
if you really mustif 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
- Download the tar.gz for specific version
- Extract using
tar zxvf myapp.tar.gz
- cd into the directory by step 2
- 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
andImport
of theDESCRIPTION
file, to meet the dependencies and see if they are installed by examining the object returned byinstalled.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
How to Download a Large Binary File with Rcurl *After* Server Authentication
Ggplot Inserting Space Before Degree Symbol on Axis Label
How to Print the Name of Current Row When Using Apply in R
Automatically Detect Date Columns When Reading a File into a Data.Frame
Expanding Factor Interactions Within a Formula
How to Set Factor Levels to the Order They Appear in a Data Frame
Ggplot2: How to Reduce Space Between Narrow Width Bars, After Coord_Flip, and Panel Border
R Dplyr Filter Based on Matching Search Term with First Words of Any Work in Select Columns
How to Represent Polynomials with Numeric Vectors in R
Forest Plot with Table Ggplot Coding
Pull Nth Day of Month in Xts in R
Mathematical Expression in Axis Label
R Cmd Check Latex Error: Fatal PDFlatex - Gui Framework Cannot Be Initialized
How to Plot a Stacked Bar with Ggplot
R - Data Frame - Convert to Sparse Matrix