R/download-cran-package.R

Defines functions download_cran_package_source

#' @importFrom remotes download_version
#' @export
download_cran_package_source <- function(package, version = NULL, dest_dir = NULL,
                                  repos = getOption("repos")) {
  archive <- remotes::download_version(package, version, repos)
  on.exit(unlink(archive))

  utils::untar(archive, exdir = dest_dir)

  dir <- file.path(dest_dir, package)
  if (!dir.exists(dir)) {
    stop("Expected extracted sources in ", dir, " but it does not exist")
  }

  dir
}
PRL-PRG/rapr documentation built on Oct. 18, 2022, 5:45 a.m.