Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to download (with out install) package from github

Tags:

r

devtools

Is there anyway to download the zipped package from github and not have it installed?

For example running:

devtools::install_github("tidyverse/tidyr")

downloads and installs at once. Is there anything equivalent to

download.packages("tidyr", destdir = "path")

For github packages?

like image 221
Rafael Avatar asked Jan 22 '26 08:01

Rafael


2 Answers

If you want to download a GitHub repository (in this case tidyr package) you can use download.file and copy the link in the GitHub "Clone or download" button by right click in it.

download.file(url = "https://github.com/tidyverse/tidyr/archive/master.zip",
              destfile = "tidyr.zip")

And if you want a function to do it, one possible solution could be (it will download on current working directory):

download_git <- function(repo_name, repo_url, install = FALSE){

   url_git <- paste0(file.path(repo, "archive", "master"), ".zip")
   download.file(url = url_git,
                 destfile = paste0(repo_name, "-master.zip"))

   if(install) {

      unzip(zipfile = paste0(repo_name, "-master.zip"))

      devtools::install(paste0(repo_name,"-master"))    
   }
}

and you here's an example with how to use it (with installing option):

download_git(repo_name = "tidyr", 
             repo_url = "https://github.com/tidyverse/tidyr", 
             install = TRUE)
like image 144
patL Avatar answered Jan 24 '26 04:01

patL


I think you may use:

repo <- "tidyverse/tidyr"
download.file(
  url = paste0("https://api.github.com/repos/", repo, "/tarball/master"), 
  destfile = "~/tidyr.tar.gz"
)

If you want to do it via a package, you could use remotes:

x <- list(host = "api.github.com", repo = "tidyr", username = "tidyverse", ref = "master")
tmpFile <- remotes:::remote_download.github_remote(x)
file.rename(tmpFile, "~/tidyr.tar.gz")

Which will effectively be equivalent to the above. Note the remote_download.github_remote function is not exported, so not the "official" way of using it.

like image 23
Jozef Avatar answered Jan 24 '26 03:01

Jozef



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!