How to install R packages with many dependencies
Step 1: Get packages and dependencies
#### run on local machine ####
## Script input parameters
list_packages <- c( "bigrquery", "tools" ) # replace with your list of package names
working_path <- tempdir() # replace with your output folder
## Script starts
require(tools)
# search dependent packages
dependencyNames <- unlist(
tools::package_dependencies(packages = list_packages, db = available.packages(),
which = c("Depends", "Imports"),
recursive = TRUE))
# sort from leaf to root
packageNames <- union(rev(dependencyNames), list_packages)
# create a output folder in working_path with name "dpendencies_for_<list_packages>"
output_dir <- file.path(working_path, paste(c("dependencies_for", list_packages), collapse = "_"))
dir.create(output_dir)
# Download the packages to the output directory.
pkgInfo <- download.packages(pkgs = packageNames, destdir = output_dir, type = "both")
# Save just the package file names (basename() strips off the full paths leaving just the filename)
write.csv(file = file.path(output_dir,"pkgFilenames.csv"), basename(pkgInfo[, 2]), row.names = FALSE)
# Zip packages and list in output_dir
zip(paste0(output_dir, ".zip"), output_dir)
message("Find resulting zip file in ", paste0(output_dir, ".zip"))Step 2: Upload the zipped packages to Sandbox
Step 3: Unzip and install in Sandbox
PreviousHow to install a R package into Sandbox?NextInstall R and Python packages from the local Sandbox repository
Last updated
Was this helpful?