Sometimes I need to run old codes in R which have been written some time ago using versions of packages different from what I use now with my current R version. When I do not need to update and correct the script with the newer functions of the current packages, but only to ckeck the results of those scripts, what is the safer way to go? Till know I have found two possibilities.
- Installing multiple R versions with their associated 'old' packages and shifting from one version to another as needed if this is possible maybe from rstudio.
- Having only one R version (assuming this would be a relatively recent one) and using old packages when needed, in case this doesn't get into dependencies problems for using old packages with a newer version of R.
The first option was a total disaster for me as I tried to install other versions of R in different ways, also had to "tune" my debian distribution (bullseye) to accept the latest R version, it became unstable and finally I had to format my PC. Related questions here and here, but before giving the suggested solutions a try, I wanted to know if other options exist. So I would appreciate any insights about the easier and safer way of running old scripts with their old packages/functions.
This works quite well by taking advantage of the ability of R to use different library paths. You can set these via
.libPaths()
easily.As a concrete example, I happen to like using
roxygen2
version 6.0.1. So I keep it in a directory my 'normal' R installation does not know about. In a helper script (as I also like to use this from the command-line) I then doand on a machine with that directory present, it will be prefixed to the library path and that older roxygen version is used in this session.
You can easily generalize this. We have done so for continuous integration and other use cases.
Another example is e.g. provided by my use of
r-devel
as it has its own library path (so that I can have package compiled byr-devel
followed by the system one (so that I do not have to rebuild all packages):