Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only download sources of a package and all dependencies

Tags:

r

packages

I am wondering if there's a way to use install.packages() or other related functions to do the following: only download the sources (i.e. tar.gz files) of the specified packages and all their dependencies into a specified folder (on Windows).

One reason to do this is: say I have a Linux account that is not enabled for internet access. In order to install the packages on the Linux machine, I would first download all the needed sources on my Windows machine, then ftp them over to the Linux machine, and install them on the Linux machine using

  install.packages('/home/me/R/Packages/blah.tar.gz', repos = NULL)
like image 430
Prasad Chalasani Avatar asked Jun 08 '11 15:06

Prasad Chalasani


People also ask

Which command is used for installing all the dependencies of the components?

npm install (in a package directory, no arguments): Install the dependencies to the local node_modules folder. In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.

What does Pip download do?

The pip download command can be used to download packages and their dependencies to the current directory (by default), or else to a specified location without installing them.


3 Answers

I recently had a problem where I wanted to download all dependencies and I've solved it thus:

Say I want all the dependencies and imports of ggplot2 and MASS:

getPackages <- function(packs){   packages <- unlist(     tools::package_dependencies(packs, available.packages(),                          which=c("Depends", "Imports"), recursive=TRUE)   )   packages <- union(packs, packages)   packages }  packages <- getPackages(c("ggplot2", "MASS")) 

I can now download the packages to another directory.

download.packages(packages, destdir="whereyouactuallywantthefiles",                    type="source") 

From there if you want to make a local repo on your Linux PC, follow the instructions here.

like image 126
sebastian-c Avatar answered Sep 28 '22 11:09

sebastian-c


Try download.packages(c("xts", "rms"), "c:/TEMP", .....) instead of install.packages(); you can directly give it a target directory in the 2nd argument.

Edit several years later: As stated above on other answers and comments, by now several helper functions have been added to R's tools and utils packages. R 3.4.0 will have tools::CRAN_package_db() to download the top-level PACKAGES.rds file (and of course you could just combine download.file() and readRDS() for that too).

like image 33
Dirk Eddelbuettel Avatar answered Sep 28 '22 11:09

Dirk Eddelbuettel


There are now better options for this in the tools package that comes with base R: package_dependencies(). See for example, the Answer from @sebastian-c and this recent Q&A for a related use-case.


There is an unexported getDependencies() function in the utils package. I haven't studied how it works, but combining that with @Dirk's Answer should get you most of the way there.

Basically though, it appears you use it like:

utils:::getDependencies(pkgs, dependencies, available, lib)

where pkgs is the character vector of packages to install, dependencies is a character vector of types of dependencies (Depends, Enhances etc) that you want, available is the output from available.packages() and lib is the library location for the packages within which dependencies are evaluated.

If you debug install.packages() it is basically doing the getDependencies() step then @Dirk's download.packages() step before it actually starts installing anything.

like image 32
Gavin Simpson Avatar answered Sep 28 '22 10:09

Gavin Simpson