install_package_plan_parallel <- function(plan, lib, repo_dir,
num_workers, quiet) {
## We need to install binaries first, because install.packages()
## cannot install a mix of binaries and sources, apparently, if some
## binaries do not have source versions.
plan <- install_package_plan_binaries(plan, lib, repo_dir, num_workers,
quiet)
## Now we can install the sources, in parallel
install_package_plan_sources(plan, lib, repo_dir, num_workers, quiet)
}
install_package_plan_binaries <- function(plan, lib, repo_dir,
num_workers, quiet) {
## Early exit if nothing to do
to_install <- plan$type != "installed" & plan$binary
if (!any(to_install)) return(plan)
if (!quiet) {
message("\n---> Installing binary packages\n")
pkg_ver <- paste(plan$package[to_install], plan$version[to_install])
cat(strwrap(paste(pkg_ver, collapse = ", ")), sep = "\n")
}
src_pkg_dir <- utils::contrib.url(repo_dir, "source")
pkg_dir <- utils::contrib.url(repo_dir, "binary")
## This platform does not have binaries, at least not natively.
## So what we will pretend that the binary packages are source packages.
## We do the same if the platform is not macOS or Windows, as these are
## the ones natively supporting binaries
if (src_pkg_dir == pkg_dir || (!is_windows() && !is_macos())) {
plan$binary <- FALSE
return(plan)
}
mkdirp(pkg_dir)
type <- if (is_windows()) "win.binary" else "mac.binary"
tools::write_PACKAGES(pkg_dir, type = type)
with_options(
list(Ncpus = num_workers, repos = paste0("file:///", repo_dir)),
utils::install.packages(plan$package[to_install], lib, type = "binary",
quiet = quiet)
)
## TODO: update plan
plan
}
install_package_plan_sources <- function(plan, lib, repo_dir,
num_workers, quiet) {
## Early exit if nothing to do
to_install <- plan$type != "installed" & !plan$binary
if (!any(to_install)) return(plan)
if (!quiet) {
message("\n---> Installing source packages\n")
pkg_ver <- paste(plan$package[to_install], plan$version[to_install])
cat(strwrap(paste(pkg_ver, collapse = ", ")), "", sep = "\n")
}
## We do a lot of IO, so we can usually make use of more processes
## than the number of processors
num_workers <- num_workers * 2
pkg_dir <- utils::contrib.url(repo_dir, "source")
mkdirp(pkg_dir)
tools::write_PACKAGES(pkg_dir, type = "source")
with_options(
list(Ncpus = num_workers, repos = paste0("file:///", repo_dir)),
utils::install.packages(plan$package[to_install], lib, type = "source",
quiet = quiet)
)
## TODO: update plan
plan
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.