Multiple R Versions
The Building R and R Contribution Workflow tutorials use the simplest set up, working on a single copy of the R sources.
It can be helpful to work with multiple versions of R:
- to compare your modifications with an unmodified copy, e.g. to compare speed or memory usage, or
- to work on independent changes, so that each patch only contains the changes for one bug fix or new feature.
You can build multiple R versions in the same Codespaces environment.
-
First choose a name for the R version. This will be used to identify the version and to name the build/source directory. By default, we use the name
r-devel
and the environment variablesBUILDDIR
andTOP_SRCDIR
are set to match.For illustration, we will use
r-devel-raw
, which you might use to name a version of R that you never modify. -
You can set the
BUILDDIR
andTOP_SRCDIR
environment variables to match your chosen name using theset_build_r
function:-
Open a terminal in the codespace.
-
Run the
set_build_r
function with your chosen name as the argument, e.g.The new values of the environment variables will be printed as confirmation:
-
-
If you have an unmodified build of R-devel using the default name of
r-devel
, you can simply copy the sources and the build to the new directories withrsync
:rsync -a "$(dirname "$BUILDDIR")/r-devel/"* $BUILDDIR rsync -a "$(dirname "$TOP_SRCDIR")/r-devel/"* $TOP_SRCDIR
Otherwise you can follow the steps in the Building R tutorial to checkout the R sources and build R using the new source and build directories.
-
Once you have a build of R under the new build directory, you will see your chosen name in the choices when running the
which_r
script to select the version of R to run in new terminals, e.g.
Note
BUILDDIR
and TOP_SRCDIR
will be set to the defaults using the label r-devel
whenever a new bash terminal is opened, e.g. when the codespace is restarted.
Whenever following instructions that use these variables to refer to the build and source directory, be sure they are pointing to the desired version!
You can check the values any time with
and switch with set_build_r <name>
.