Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

r - Only download sources of a package and all dependencies

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...