Rafael
Rafael

Reputation: 3196

how to download (with out install) package from github

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?

Upvotes: 3

Views: 11412

Answers (2)

Jozef
Jozef

Reputation: 2737

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.

Upvotes: 1

patL
patL

Reputation: 2299

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)

Upvotes: 2

Related Questions