Skip to content

Commit

Permalink
clean up non-test related R CMD check problems (#23)
Browse files Browse the repository at this point in the history
* add `magrittr` to Imports
* clean up `addLocalPackage` and `.listFiles`

**NOTE** test4 still failing
  • Loading branch information
achubaty committed Apr 15, 2016
1 parent 4f3c6b2 commit aeb42f0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 33 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Date: 2016-04-15
Imports:
graphics,
httr,
magrittr,
methods,
stats,
tools,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ importFrom(graphics,title)
importFrom(httr,GET)
importFrom(httr,content)
importFrom(httr,stop_for_status)
importFrom(magrittr,'%>%')
importFrom(methods,is)
importFrom(stats,reshape)
importFrom(stats,setNames)
Expand Down
41 changes: 27 additions & 14 deletions R/addPackages.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if (getRversion() >= "3.1.0") {
utils::globalVariables(c("."))
}

#' Check for previous versions of packages in a miniCRAN repository.
#'
#' Checks for previous versions, and returns the file paths for packages with multiple versions. You can subsequently decide which version to keep.
Expand Down Expand Up @@ -152,19 +156,23 @@ addOldPackage <- function(pkgs=NULL, path=NULL, vers=NULL,

#' List pre-built packages in a directory based on file extension
#'
#' @param path Character sting specifying the directory containing packages to be added.
#' @param pkgs Character vector of package names
#' @param path Character string specifying the directory containing packages to be added.
#' @param type Character indicating the package type (e.g., "source", "win.binary", etc.).
#'
#' @return Installs the packages and returns the new package index.
#'
#' @rdname listFiles
#' @docType methods
#'
#' @importFrom magrittr '%>%'
#'
#' @examples
#' \dontrun{
#' .listFiles('path/to/my/packages', type = "source")
#' }
#'
.listFiles <- function(path, type) {
.listFiles <- function(pkgs, path, type) {
stopifnot(dir.exists(path))
pattern <- switch(type,
mac.binary = ".tgz",
Expand Down Expand Up @@ -229,10 +237,12 @@ addOldPackage <- function(pkgs=NULL, path=NULL, vers=NULL,
#'
#' @examples
#' \dontrun{
#' addLocalPackage("myPackage", "path/to/my/prebuilt/package", "path/to/my/miniCRAN/repo")
#' addLocalPackage("myPackage", "path/to/my/package/sourcecode", "path/to/my/miniCRAN/repo", build=TRUE)
#' addLocalPackage("myPackage", "path/to/my/prebuilt/package",
#' "path/to/my/miniCRAN/repo")
#' addLocalPackage("myPackage", "path/to/my/package/sourcecode",
#' "path/to/my/miniCRAN/repo", build=TRUE)
#' }
#'addLocalPackage("myPackage", "path/to/my/prebuilt/package", "path/to/my/miniCRAN/repo")
#'
addLocalPackage <- function(pkgs, pkgPath, path, type = "source",
Rversion = R.version, writePACKAGES = TRUE,
deps = FALSE, quiet = FALSE, build = FALSE) {
Expand All @@ -253,8 +263,9 @@ addLocalPackage <- function(pkgs, pkgPath, path, type = "source",
}

# get list of pre-built packages for each type, filter by pkgs to be added
sapply(type, function(type) {
files <- .listFiles(path = pkgPath, type = type)
sapply(type, function(t) {
repoPath <- file.path(path, repoPrefix(t, version))
files <- .listFiles(path = pkgPath, type = t)

# check for previous package version and omit if identical
prev <- checkVersions(pkgs)
Expand All @@ -271,21 +282,23 @@ addLocalPackage <- function(pkgs, pkgPath, path, type = "source",
# copy other packages to their respective folders
lapply(files, function(x) {
paste("copying", x)
file.copy(from = file.path(pkgPath, x),
to = file.path(repoPath, repoPrefix(type, version), x))
system(paste0("chmod a-x ", src, "/", x))
file.copy(from = file.path(pkgPath, x), to = file.path(repoPath, x))
system(paste0("chmod a-x ", repoPath, "/", x))
})
if (!all(file.exists(file.path(src, src.files)))) {
warning("some source packages could not be added.")

# check to ensure they all copied successfully
copied <- file.exists(file.path(repoPath, files))
if (!all(copied)) {
warning("the following ", t, " packages were not copied:\n",
paste(files[!copied], sep = ", "))
}

# remove previous package versions
if (length(prev[-same]) > 0) unlink(prev[-same])
})


# write package index for each folder:
index <- updateRepoIndex(path = repoPath, type = type, Rversion = Rversion)
index <- updateRepoIndex(path = path, type = type, Rversion = Rversion)

return(invisible(index))
}
18 changes: 12 additions & 6 deletions man/addLocalPackage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions man/listFiles.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 6 additions & 11 deletions tests/testthat/test-3-makeRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ if(file.exists(repo_root)) unlink(repo_root, recursive = TRUE)
types <- c("source", "win.binary", "mac.binary", "mac.binary.mavericks")
names(types) <- c("source", "win.binary", "mac.binary", "mac.binary")

for(pkg_type in names(types)){
for(pkg_type in names(types)){

test_that(sprintf("makeRepo downloads %s files and builds PACKAGES file", pkg_type), {

skip_on_cran()
skip_if_offline()

pdb <- pkgAvail(repos = revolution, type=pkg_type)
pkgList <- pkgDep(pkgs, availPkgs = pdb, repos=revolution, type=pkg_type, suggests=FALSE)
prefix <- miniCRAN:::repoPrefix(pkg_type, R.version)
dir.create(repo_root, recursive = TRUE, showWarnings = FALSE)

makeRepo(pkgList, path=repo_root, repos=revolution, type=pkg_type, quiet=TRUE)

expect_true(
miniCRAN:::.checkForRepoFiles(repo_root, pkgList, prefix)
)
Expand All @@ -39,12 +39,7 @@ for(pkg_type in names(types)){
pkgList %in% pkgAvail(repos = repo_root, type=pkg_type)[, "Package"]
)
)

})

}



unlink(repo_root, recursive = TRUE)

0 comments on commit aeb42f0

Please sign in to comment.