Description Usage Arguments Details Value Note Author(s) Examples
View source: R/RecreateLibrary.R
Recreate an existing library on a new installation of R.
The SavePackageDetails
function writes the details of installed packages to a text file.
And the RecreateLibrary
function reads this file and downloads and installs any
‘missing’ packages from the Comprehensive R Archive Network (CRAN),
CRAN-like repositories, and local package-installation files.
1 2 3 4 5 6 7 8 9 10 11 12 |
file |
'character' string.
Name of the file for reading (or writing) the list of package details.
For a file name that does not contain an absolute path,
the name is assumed relative to the current working directory (see |
lib |
'character' vector.
Library tree(s) to search through when locating installed packages (see |
repos |
'character' vector.
Base URL(s) of the CRAN-like repositories (includes CRAN) to use when installing packages.
For example, the URL of the RStudio sponsored CRAN mirror is |
snapshot |
'logical' flag, 'Date', or 'character' string.
Calendar date for a CRAN snapshot in time,
see the Microsoft R Application Network
(MRAN) website for details.
If true, the snapshot date is read from the first line of the package-details |
local |
'character' vector. Paths to local repositories. Packages are installed from local files in these directories. Files can contain binary builds of packages (‘.zip’ on Windows and ‘.tgz’ on macOS) or be source packages (‘.tar.gz’). |
versions |
'logical' flag.
If true, installed package versions will be identical to version numbers stored in the package-details |
parallel |
'logical' flag or 'integer' count. Whether to use parallel processes for a parallel install of more than one source package. This argument can also be used to specify the number of cores to employ. |
quiet |
'logical' flag. Whether to reduce the amount of output. |
pkg |
'character' vector.
Names of package(s) located under |
A typical workflow is as follows:
Run the SavePackageDetails()
command on an older version of R.
It will print to a text file a complete list of details for packages located under your current R library tree(s).
If the older version of R no longer needed, uninstall it.
Then, on a freshly installed version of R with the inlmisc package available,
run the RecreateLibrary()
command.
It will download and install the packages listed in the package-details file
.
The type of package to download and install from CRAN-like repositories is binary on Windows and some macOS builds, and source on all others. Package installation from a local ‘.tar.gz’ file is always a source installation. If a package is installed from source, and it contains code that needs compiling, you must have a working development environment. On Windows, install the Rtools collection and have the PATH environment variable set up as required by Rtools. On macOS, install Xcode from the Mac App Store. And on Linux, install a compiler and various development libraries.
Daily snapshots of CRAN are stored on MRAN and available as far back as September 17, 2014.
Use the snapshot
argument to install older package versions from MRAN.
Newer versions of R may not be compatible with older versions of packages.
To avoid any package installation issues,
install the R version that was available from CRAN on the
snapshot date.
The package-details file
is of the following format:
1 2 3 4 5 6 |
Where the first two lines are reserved for the timestamp and R-version number, respectively. And package data are stored in a tabular structure, that is, data-table values are separated by a TAB character. The data format is flexible enough to add additional extraneous metadata and table fields, for example,
1 2 3 4 5 6 7 8 |
The SavePackageDetails
function returns (invisibly) the MD5 hash of the package-details file
content.
Any changes in the file content will produce a different MD5 hash.
Use the md5sum
function to verify that a file has not been changed.
The RecreateLibrary
function returns (invisibly) NULL
.
This package-installation method does not offer one-hundred percent reproducibility of existing R libraries. Alternative methods, that offer better reproducibility, are available using the checkpoint and packrat packages; both of which provide robust tools for dependency management in R.
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # Run on old version of R
SavePackageDetails()
# Run on new version of R, and ensure 'inlmisc' package is available.
if (interactive()) {
repos <- c(CRAN = "https://cloud.r-project.org/")
if (system.file(package = "inlmisc") == "")
utils::install.packages("inlmisc", repos = repos["CRAN"],
dependencies = TRUE)
inlmisc::RecreateLibrary(repos = repos)
}
# Clean up example
file.remove("R-packages.tsv")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.