miniCRAN icon indicating copy to clipboard operation
miniCRAN copied to clipboard

Add capability to add a github package to a miniCRAN repo

Open andrie opened this issue 10 years ago • 9 comments

This is a feature that gets requested often

Related to:

  • #23 new function to add a local package
  • #9 Add capability to read package data from local file
  • #10 Add capability to read package data from github

andrie avatar Dec 16 '14 16:12 andrie

see devtools::install_remote() to see how the package source bundle is downloaded. from there, #23's addLocalPackage can take over

achubaty avatar Apr 15 '16 21:04 achubaty

This would be handy

stephlocke avatar May 04 '17 13:05 stephlocke

Here's an example based on achubaty's comment

addGithubPackage <- function(githubPath,...){
    packageName <- basename(githubPath)
    exDir <- file.path(tempdir(),packageName)
    if(file.exists(exDir)) unlink(exDir, recursive=TRUE)
    zipFile <- file.path(tempdir(),paste0(packageName,".zip"))
    download.file(paste0(githubPath,"/","zipball/master"),zipFile)
    unzip(zipFile, exdir = exDir)
    file.rename(list.files(exDir,full.names=TRUE)[1],file.path(exDir,packageName))
    addLocalPackage(packageName,exDir,...)
}
addGithubPackage(githubPath="https://github.com/js229/Vennerable/",path=reposPath,build=TRUE)

msteijaert avatar Mar 20 '18 14:03 msteijaert

@msteijaert I resolved a file path error by setting mode = "wb" in download.file(). Thank you, for the function.

OS: Windows 7 R: 3.4.4

seasmith avatar Apr 17 '18 05:04 seasmith

@msteijaert's code doesn't work anymore. I get the error Error: No files found in path with extension '.tar.gz'

StaffanBetner avatar Mar 03 '21 11:03 StaffanBetner

@msteijaert thank you for taking a first crack at this. I've implemented a version of your function on the 50-addPackageGitHub branch, though it needs work. See the commit message there.

@msteijaert's code doesn't work anymore. I get the error Error: No files found in path with extension '.tar.gz'

Can you post the code you used? I can't reporduce the error.

achubaty avatar Jul 16 '21 15:07 achubaty

Hi! I needed this functionality and took the code from the branch 50-addPackageGitHub and extended it to support private repos etc by calling the appropriate functions in the remotes package.

The end result is below. Feel free to add it to the package or let me know if you would like a proper pull request.

addPackageGitHub <- function(repo, username = NULL, ref = "master", subdir = NULL, auth_token = remotes:::github_pat(quiet), ...) {
  packageName <- basename(repo)
  exDir <- file.path(tempdir(), packageName)
  if (dir.exists(exDir)) unlink(exDir, recursive = TRUE)

  remote <- remotes:::github_remote(repo = repo, username = username, ref = ref, subdir = subdir, auth_token = auth_token)
  tarFile <- remotes:::remote_download(remote)

  untar(tarFile, exdir = exDir)
  file.rename(list.files(exDir, full.names = TRUE)[1], file.path(exDir, packageName))

  ## TODO: addLocalPackage() does not add the dependencies of the locally built package!
  addLocalPackage(packageName, exDir, ..., build = TRUE)
}

addPackageGitHub("user/repo", auth_token=github_token, path=miniCRAN_dir)

jonlachmann avatar Jan 24 '22 14:01 jonlachmann