#' Download packages of a package installation plan
#'
#' Download packages of a package installation plan, into the R
#' temporary directory.
#'
#' It downloads all files in parallel.
#'
#' It requires the libcurl capability currently, see [capabilities()].
#'
#' @param plan Package installation plan, as created by the
#' pkgdepends package.
#' @param quiet If `TRUE`, suppress status messages.
#' @return The updated package plan, with additional columns:
#' * `download_dir`: the directory of the downloaded package,
#' * `status`: download status,
#' * `file`: path to the downloaded file.
#'
#' @export
#' @importFrom utils download.file
#' @seealso [install_package_plan()] for installing the packages in the
#' plan.
download_package_plan <- function(plan, quiet = FALSE) {
if (!capabilities("libcurl")) {
stop("Needs capability 'libcurl', and this R installation does not ",
"support that.")
}
## TODO: support alternative URLs
## TODO: caching?
## TODO: handle errors
if (!quiet) message("\n---> Downloading packages\n")
urls <- map_chr(plan$sources, "[[", 1)
mkdirp(ddir <- file.path(tempdir(), "pkg_install"))
dests <- file.path(ddir, plan$target)
mkdirp(dirname(dests))
ret <- download.file(urls, dests, mode = "wb", quiet = quiet,
method = "libcurl")
if (ret != 0) stop("Some package downloads failed")
plan$download_dir <- normalizePath(ddir, winslash = "/")
plan$status <- "OK"
plan$file <- dests
plan
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.