Skip to content

Commit

Permalink
fix error: addPackage & addOldPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
achubaty committed Nov 17, 2014
1 parent 7081c6f commit f18310a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
27 changes: 17 additions & 10 deletions R/addPackages.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ pkgFileExt <- function(type) {

getPkgVersFromFile <- function(file) {
file <- grep("\\.(tar\\.gz|zip|tgz)$", basename(file), value=TRUE)
file <- sapply(strsplit(file, pkgFileExt(type)), "[[", 1)
pkg <- sapply(strsplit(file, "_"), "[[", 1)
vers <- sapply(strsplit(file, "_"), "[[", 2)
df <- data.frame(package=pkg, version=vers)
return(df[order(df$package),])
if (length(file)) {
file <- sapply(strsplit(file, "\\.tar\\.gz"), "[[", 1)
file <- sapply(strsplit(file, "\\.zip"), "[[", 1)
file <- sapply(strsplit(file, "\\.tgz"), "[[", 1)
pkg <- sapply(strsplit(file, "_"), "[[", 1)
vers <- sapply(strsplit(file, "_"), "[[", 2)
df <- data.frame(package=pkg, version=vers, stringsAsFactors=FALSE)
return(df[order(df$package),])
} else {
return(NULL)
}
}

readDescription <- function (file) {
Expand Down Expand Up @@ -106,7 +112,7 @@ addPackageListingGithub <- function(pdb=pkgAvail(), repo, username=NULL, branch=
#' @param Rversion numeric version of the R system for which to fetch packages.
#' See \code{\link{R_system_version}}.
#'
#' @return Returns filepaths to packages with multiple versions for removal.
#' @return Returns invisibly the filepaths to packages with multiple versions for removal.
#'
#' @export
#' @docType methods
Expand All @@ -124,12 +130,13 @@ checkVersions <- function(pkgs=NULL, path=NULL, type="source",
files = sapply(pkgs, function(x) list.files(pkgPath, pattern=paste0(x,"_")) )
}
files = unlist(files)
pkgFiles = grep("\\.(tar\\.gz|zip|tgz)$", basename(files), value=TRUE)

# identify duplicate packages and warn the user
pkgs = sapply(strsplit(files, "_"), "[[", 1)
dupes = pkgs[duplicated(pkgs)]
if (length(dupes)) warning("Duplicate package(s):", dupes)
return(file.path(pkgPath, files))
if (length(dupes)) warning("Duplicate package(s): ", paste(dupes, collapse=", "))
return(invisible(file.path(pkgPath, pkgFiles)))
}

################################################################################
Expand Down Expand Up @@ -173,9 +180,9 @@ addPackage <- function(pkgs=NULL, path=NULL, repos=getOption("repos"),
download=TRUE, writePACKAGES=FALSE)
if (length(prev)>0) {
curr <- checkVersions(pkgs=pkgs, path=path, type=type, Rversion=Rversion)
old <- setdiff(prev, curr)
old <- intersect(prev, curr)
message("Removing previous versions of newly added packages:")
message(basename(old))
message(paste(basename(old), collapse=", "))
file.remove(old)
}
if (writePACKAGES) {
Expand Down
2 changes: 1 addition & 1 deletion inst/examples/example_updatePackages.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pkgList
# download old source package version and create repo index
oldVers <- data.frame(package=c("foreach", "codetools", "iterators"),
version=c("1.4.0", "0.2-7", "1.0.5"))
addOldPackage(pkgList, path=pth, vers=oldVers, type="source")
addOldPackage(pkgList, path=pth, vers=oldVers$version, type="source")
# NOTE: older binary versions would need to be build from source

# Check if updated packages are available
Expand Down
6 changes: 3 additions & 3 deletions man/checkVersions.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ checkVersions(pkgs = NULL, path = NULL, type = "source",
See \code{\link{R_system_version}}.}
}
\value{
Returns filepaths to packages with multiple versions for removal.
Returns invisibly the filepaths to packages with multiple versions for removal.
}
\description{
Checks for previous versions, and returns the file paths for packages with
Expand Down Expand Up @@ -68,8 +68,8 @@ pkgList
tools::write_PACKAGES(pkgPathBin, type="win.binary")

# Add new packages (from CRAN) to the miniCRAN repo
add.packages.miniCRAN("raster", path=pth, repos=revolution, type="source")
add.packages.miniCRAN("raster", path=pth, repos=revolution, type="win.binary")
addPackage("raster", path=pth, repos=revolution, type="source")
addPackage("raster", path=pth, repos=revolution, type="win.binary")

# Delete temporary folder
unlink(pth, recursive=TRUE)
Expand Down
2 changes: 1 addition & 1 deletion man/oldPackages.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pkgList
# download old source package version and create repo index
oldVers <- data.frame(package=c("foreach", "codetools", "iterators"),
version=c("1.4.0", "0.2-7", "1.0.5"))
addOldPackage(pkgList, path=pth, vers=oldVers, type="source")
addOldPackage(pkgList, path=pth, vers=oldVers$version, type="source")
# NOTE: older binary versions would need to be build from source

# Check if updated packages are available
Expand Down
2 changes: 1 addition & 1 deletion man/updatePackages.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pkgList
# download old source package version and create repo index
oldVers <- data.frame(package=c("foreach", "codetools", "iterators"),
version=c("1.4.0", "0.2-7", "1.0.5"))
addOldPackage(pkgList, path=pth, vers=oldVers, type="source")
addOldPackage(pkgList, path=pth, vers=oldVers$version, type="source")
# NOTE: older binary versions would need to be build from source

# Check if updated packages are available
Expand Down

0 comments on commit f18310a

Please sign in to comment.