knitr::opts_chunk$set( comment = "#>", tidy = FALSE, error = FALSE, fig.width = 8, fig.height = 8)
Backup and Restore Certain CRAN Package Versions
Create a snapshot of your installed CRAN packages with 'snap', and then use 'restore' on another system to recreate exactly the same environment.
devtools::install_github("mangothecat/pkgsnap")
library(pkgsnap)
For this experiment we create a new library directory, and install
some packages there. We will then remove this directory entirely,
and recreate it using pkgsnap
.
lib_dir <- tempfile() dir.create(lib_dir)
We make this new library directory the default:
.libPaths(lib_dir)
The new library directory is currently empty:
installed.packages(lib_dir)[, c("Package", "Version")]
Let's install some packages here. Note that the dependencies of these packages will be also installed.
install.packages(c("testthat", "pkgconfig")) installed.packages(lib_dir)[, c("Package", "Version")]
We will now create a snapshot, and then scrap the temporary package library.
snapshot <- tempfile() snap(to = snapshot) read.csv(snapshot)[1:5,] unlink(lib_dir, recursive = TRUE)
Create a new package library.
new_lib_dir <- tempfile() dir.create(new_lib_dir) .libPaths(new_lib_dir)
Finally, recreate the same set of package versions, in a new package library.
restore(snapshot) installed.packages(new_lib_dir)[, c("Package", "Version")]
MIT © Mango Solutions.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.