Last active
November 17, 2017 12:50
-
-
Save jennybc/4ffc1607d07ed3b025dc to your computer and use it in GitHub Desktop.
Install a package from, e.g., GitHub into a temporary library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 2015-11-11 NOTE! | |
## with_libpaths() is one of the functions removed (well, deprecated, for now) from | |
## devtools | |
## it's in withr now! | |
## see newer script below!!! | |
library(devtools) # with_lib(), install_github() | |
tmp_lib <- "~/tmp/tmp_lib" | |
dir.create(tmp_lib) | |
## upgrade or downgrade a package here | |
## following example is upgrading to bleeding edge devel version | |
with_lib(tmp_lib, install_github("codegenius/alphapkg", ref = "bleeding-edge")) | |
## but this could also be a downgrade to the CRAN/released version! | |
## restart R | |
## explicitly load the affected packages from the temporary library | |
tmp_lib <- "~/tmp/tmp_lib" | |
library(alphapkg, lib.loc = tmp_lib) | |
## your experimentation goes here | |
## done? clean up! | |
unlink(tmp_lib, recursive = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(withr) | |
library(devtools) | |
tmp_lib <- "~/tmp/tmp_library" | |
dir.create(tmp_lib) | |
## upgrade or downgrade a package here | |
with_libpaths(tmp_lib, | |
install_github("dill/beyonce"), | |
"prefix" | |
) | |
## restart R | |
## explicitly load the affected packages from the temporary library | |
library(beyonce, lib.loc = tmp_lib) | |
## your experimentation goes here | |
## done? clean up! | |
unlink(tmp_lib, recursive = TRUE) |
works with bioconductor also?
@jennybc My switchr package provides an abstraction for doing exactly this, including (trying hard to) unload already loaded versions of packages and protecting you from accidentally mixing.
See http://arxiv.org/abs/1501.02284 and/or the docs/vignette at http://github.com/gmbecker/switchr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jeroenooms points out you could also set up the temporary library like so
tmp_lib <- file.path(tempdir(), ".lib")
if this will be a very short-lived experiment and you won't even restart R. Advantage: the temporary library will get nuked automatically. If you do this, make sure to begin the whole process in a fresh R session, i.e. there's no risk the affected packages are already loaded.