Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addPackage fails to copy files from local repository #83

Closed
johndoe28 opened this issue Apr 26, 2017 · 3 comments
Closed

addPackage fails to copy files from local repository #83

johndoe28 opened this issue Apr 26, 2017 · 3 comments
Labels
Milestone

Comments

@johndoe28
Copy link

johndoe28 commented Apr 26, 2017

Scenario

  1. I have a local repository (see variable ascCRAN.path below) where I build source packages using RStudio.
  2. I have a release miniCRAN repository (see variable miniCRAN.path) that contain all the packages that need to be released
  3. My repos consist of my local repository, a MRAN repository and a third party repository (see variable repos.x)
  4. I call addPackage to add packages from my local repository and their dependencies to my miniCRAN repository
ascCRAN.path = "H:/X/CRANasc";

repos.x = c(
    file.path("file://",ascCRAN.path),
    "http://download.mosek.com/R/8",
    "https://mran.microsoft.com/snapshot/2017-03-15"
);

miniCRAN.path = "H:/X/CRANra";

miniCRAN::addPackage(c("rautils","env"),path = miniCRAN.path,repos = repos.x,type = "source");

Issue

miniCRAN::addPackage calls miniCRAN::makeRepo and that function trips on the bold code (see if conditional) because the variable fromLocalRepos is a vector of logicals and the “if” statement doesn’t like the vector of length > 1 in the conditional. Here are the warnings after running the addPackage line:

Warning messages:

1: In if (fromLocalRepos) { :
  the condition has length > 1 and only the first element will be used
2: In normalizePath(path.expand(path), winslash, mustWork) :
  path[2]="http://download.mosek.com/R/8": The specified path is invalid
3: In normalizePath(path.expand(path), winslash, mustWork) :
  path[3]="https://mran.microsoft.com/snapshot/2017-03-15": The specified path is invalid
4: In gsub(repoPath, path, downloaded) :
  argument 'pattern' has length > 1 and only the first element will be used

My example works only because my local repository is first element of repos.x variable. If I reorder repos.x and define it instead as shown below with the local repository last in the vector, the source packages in my local repository are no longer copied to the miniCRAN repository because the first element of fromLocalRepos logical vector is now FALSE and the if statement fails. Is there a workaround or does this require a bug fix?

repos.x = c(
    "http://download.mosek.com/R/8",
    "https://mran.microsoft.com/snapshot/2017-03-15",
    file.path("file://",ascCRAN.path)
);

makeRepo <- function(pkgs, path, repos=getOption("repos"), type="source",
                     Rversion=R.version, download=TRUE, writePACKAGES=TRUE, quiet=FALSE) {
  if(!file.exists(path)) stop("Download path does not exist")
             
  downloaded <- lapply(type, function(type) {
    pkgPath <- repoBinPath(path=path, type=type, Rversion=Rversion)
    if(!file.exists(pkgPath)) {
      result <- dir.create(pkgPath, recursive=TRUE, showWarnings = FALSE)
      if(result) {
        if(!quiet) message("Created new folder: ", pkgPath)
      } else {
        stop("Unable to create repo path: ", pkgPath)
      }
    }
    
    pdb <- pkgAvail(repos = repos, type=type, Rversion = Rversion)
    
    if(download) {
      utils::download.packages(pkgs, destdir=pkgPath, available=pdb, repos=repos,
                               contriburl = contribUrl(repos, type, Rversion),
                               type=type, quiet=quiet)
    }
  })
  
  if(download){
    
    downloaded <- downloaded[[1]][, 2]
    
    fromLocalRepos <- grepl("^file://", repos)
    if(fromLocalRepos){
      # need to copy files to correct folder
      repoPath <- gsub("^file:///", "", repos)
      repoPath   <- normalizePath(repoPath, winslash = "/")
      path       <- normalizePath(path    , winslash = "/")
      downloaded <- normalizePath(downloaded, winslash = "/")
      newPath  <- gsub(repoPath, path, downloaded)
      file.copy(downloaded, newPath)
      downloaded <- newPath
    }
  }
  
  if(writePACKAGES) updateRepoIndex(path=path, type=type, Rversion=Rversion)
  if(download) downloaded else character(0)
}
@achubaty
Copy link
Collaborator

#23 deals with adding local packages to a miniCRAN repo. Can you install from that feature branch and test to see if it meets your needs?

@johndoe28
Copy link
Author

johndoe28 commented Apr 30, 2017 via email

@andrie
Copy link
Owner

andrie commented Jun 19, 2017

I am working on merging all changes to master with a view to update to CRAN soon.

@andrie andrie added this to the v0.2.8 milestone Jun 19, 2017
@andrie andrie closed this as completed Jun 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants