Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download package zip/tar.gz file without installing

Tags:

package

r

I am looking for a function, that downloads an r package zip/tar.gz file (given its name) without installing it.

Basically install.packages(), but I want to keep the zip files at a given directory.

I did not find a way to build the URL myself given the package Name, but there seems to be one, since install.packages() works that way.

like image 580
Tlatwork Avatar asked Jan 04 '18 08:01

Tlatwork


People also ask

Can 7zip extract tar?

7-Zip can also be used to unpack many other formats and to create tar files (amongst others).


1 Answers

Using download.packages:

download.packages(pkgs = "ggplot2", destdir = "/path/to/my/libs")

Or we can get the url manually using available.packages:

myPackage <- "ggplot2"
p <- available.packages()

myPackageUrl <- paste0(
  p[ rownames(p) == myPackage, "Repository"], "/",
  myPackage, "_",
  p[ rownames(p) == myPackage, "Version"], ".tar.gz")

myPackageUrl
# [1] "https://cran.rstudio.com/src/contrib/ggplot2_2.2.1.tar.gz"

# then download
download.file(url = myPackageUrl,
              destfile = paste0("/path/to/my/libs", "/",
              basename(myPackageUrl)))
like image 164
zx8754 Avatar answered Oct 28 '22 04:10

zx8754