As the title states: is it possible to install multiple git branches of the same package side-by-side in the same R environment? I want to do some benchmarking and it would be easier to compare the two branches in the same session. I think one workaround is to change the package name in the DESCRIPTION file in the new branch, but is there a more clever way to do this with devtools
?
Sample code:
devtools::install_github("mkoohafkan/RAStestR", ref = "master")
# overwrites the prior install
devtools::install_github("mkoohafkan/RAStestR", ref = "hdf5r_transition")
In short, no. At least not without an extra layer. Read on.
While git
(the protocol, as well as the client) support "branches" akin to a virtual filesystem allowing you to switch easily, R does not.
For every package you install, one and only one version can be installed.
But don't despair, because the file system can be used as a backend, and R can then switch by adjusting the library path. This is all in help(Startup)
but it may help to be explicit.
What you can do (and I mock this here)
mkdir master; cd master; installFromBranch.R master; cd ..
mkdir featureA; cd featureA; installFromBranch.R featureA; cd ..
mkdir featureB; cd featureA; installFromBranch.R featureB; cd ..
and then in R use, say,
.libPaths("master"); library("mypackage")
or if you want a feature
.libPaths("featureA"); library("mypackage")
You can also use R_LIB_USER=featureA Rscript -e '.....someCommandHere...'
So in short: map the branches to directories into which you install and tell R about those directories.