if (FALSE) {
# simple usage, like conditional install.packages then library
opts <- Require:::.setupExample()
library(Require)
getCRANrepos(ind = 1)
Require("stats") # analogous to require(stats), but it checks for
# pkg dependencies, and installs them, if missing
if (Require:::.runLongExamples()) {
# Install in a new local library (libPaths)
tempPkgFolder <- file.path(tempdir(), "Packages")
# use standAlone, means it will put it in libPaths, even if it already exists
# in another local library (e.g., personal library)
Install("crayon", libPaths = tempPkgFolder, standAlone = TRUE)
# make a package version snapshot of installed packages
tf <- tempfile()
(pkgSnapshot(tf, standAlone = TRUE))
# Change the libPaths to emulate a new computer or project
tempPkgFolder <- file.path(tempdir(), "Packages2")
# Reinstall and reload the exact version from previous
Require(packageVersionFile = tf, libPaths = tempPkgFolder, standAlone = TRUE)
# Mutual dependencies, only installs once -- e.g., curl
tempPkgFolder <- file.path(tempdir(), "Packages")
Install(c("remotes", "testit"), libPaths = tempPkgFolder, standAlone = TRUE)
# Mutual dependencies, only installs once -- e.g., curl
tempPkgFolder <- file.path(tempdir(), "Packages")
Install(c("covr", "httr"), libPaths = tempPkgFolder, standAlone = TRUE)
#####################################################################################
# Isolated projects -- Use a project folder and pass to libPaths or set .libPaths() #
#####################################################################################
# GitHub packages
ProjectPackageFolder <- file.path(tempdir(), "ProjectA")
Require("PredictiveEcology/fpCompare@development",
libPaths = ProjectPackageFolder, standAlone = FALSE
)
Install("PredictiveEcology/fpCompare@development",
libPaths = ProjectPackageFolder,
standAlone = TRUE
) # the latest version on GitHub
############################################################################
# Mixing and matching GitHub, CRAN, with and without version numbering
############################################################################
pkgs <- c(
"remotes (<=2.4.1)", # old version
"digest (>= 0.6.28)", # recent version
"PredictiveEcology/fpCompare@a0260b8476b06628bba0ae73af3430cce9620ca0" # exact version
)
Require::Require(pkgs, libPaths = ProjectPackageFolder)
Require:::.cleanup(opts)
}
}
Run the code above in your browser using DataLab