Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  Bump version to 0.2.11
  Add mockery to Suggests
  Update docs
  Add tests to improve code coverage
  minor cleanup
  misc cleanup
  Mock without using mockery or testthat::with_mock
  More mocking experiments
  mockery(>= 0.4.0)
  Depends on mockery >= 0.4.0 #107
  stub one level less deep
  Rebuild vignettes
  Use mocking to speed up tests #107
  Remove magrittr dependency
  • Loading branch information
andrie committed Jan 15, 2018
2 parents 7b62d23 + 5075147 commit 77eace6
Show file tree
Hide file tree
Showing 66 changed files with 1,652 additions and 475 deletions.
14 changes: 7 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Package: miniCRAN
Date: 2018-01-15
Version: 0.2.11
Authors@R: c(person("Microsoft Corporation", role="cph"), person("Andrie", "de
Vries", role=c("aut", "cre"), email="[email protected]"),
Vries", role=c("aut", "cre", "cph"), email="[email protected]"),
person("Alex", "Chubaty", role="ctb", email="[email protected]"))
License: GPL-2
Copyright: Microsoft Corporation
Copyright: Microsoft Corporation, Andrie de Vries
Title: Create a Mini Version of CRAN Containing Only Selected Packages
Description: Makes it possible to create an internally consistent
repository consisting of selected packages from CRAN-like repositories.
Expand All @@ -12,29 +14,27 @@ Description: Makes it possible to create an internally consistent
subset. The user can then install packages from this repository directly,
rather than from CRAN. This is useful in production settings, e.g. server
behind a firewall, or remote locations with slow (or zero) Internet access.
Date: 2017-12-19
Version: 0.2.11.9000
URL: https://github.com/andrie/miniCRAN
BugReports: https://github.com/andrie/miniCRAN/issues
SystemRequirements: Imports the `curl` and `XML` packages. These have system
requirements on `libxml2-devel`, `libcurl-devel` and `openssl-devel`.
Imports:
graphics,
httr,
magrittr,
methods,
stats,
tools,
utils,
XML,
igraph
igraph,
Suggests:
devtools,
knitr,
rmarkdown,
testthat(>= 0.9),
covr,
withr
withr,
mockery
LazyData: true
LazyLoad: true
VignetteBuilder: knitr
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ importFrom(igraph,V)
importFrom(igraph,get.edge.attribute)
importFrom(igraph,graph.data.frame)
importFrom(igraph,plot.igraph)
importFrom(magrittr,'%>%')
importFrom(methods,is)
importFrom(stats,reshape)
importFrom(stats,setNames)
importFrom(tools,write_PACKAGES)
importFrom(utils,available.packages)
importFrom(utils,chooseCRANmirror)
importFrom(utils,compareVersion)
importFrom(utils,download.file)
importFrom(utils,download.packages)
importFrom(utils,flush.console)
importFrom(utils,installed.packages)
importFrom(utils,select.list)
9 changes: 7 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
miniCRAN v0.2.11.9000 (Release date: in development)
miniCRAN v0.2.11 (Release date: in development)
================

New features:

* Used `pkgdown` to build documentation site
* None

Other changes:

* Use `pkgdown` to build documentation site
* Speed up unit testing by mocking internal functions


miniCRAN v0.2.10.9000
Expand Down
45 changes: 20 additions & 25 deletions R/addPackages.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ addPackage <- function(pkgs = NULL, path = NULL, repos = getOption("repos"),
dupes <- with(curr.df, package[duplicated(package)])
if (length(dupes)) {
to_remove <- lapply(dupes, findPrevPackage)
if(length(unlist(to_remove))){
if (length(unlist(to_remove))) {
file.remove(prev[unlist(to_remove)])
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ addOldPackage <- function(pkgs = NULL, path = NULL, vers = NULL,
if (!file.exists(pkgPath)) dir.create(pkgPath, recursive = TRUE)

do_one <- function(x) {
result <- utils::download.file(x, destfile = file.path(pkgPath, basename(x)),
result <- download.file(x, destfile = file.path(pkgPath, basename(x)),
method = "auto", mode = "wb", quiet = quiet)
if (result != 0) warning("error downloading file ", x)
}
Expand All @@ -179,22 +179,14 @@ addOldPackage <- function(pkgs = NULL, path = NULL, vers = NULL,
#' @rdname listFiles
#' @docType methods
#'
#' @importFrom magrittr '%>%'
#'
#' @examples
#' \dontrun{
#' .listFiles('path/to/my/packages', type = "source")
#' }
#'
.listFiles <- function(pkgs, path, type) {
stopifnot(dir.exists(path))
pattern <- switch(type,
mac.binary = ".tgz",
mac.binary.leopard = ".tgz",
mac.binary.mavericks = ".tgz",
source = ".tar.gz",
win.binary = ".zip",
stop("Type ", type, "not recognised."))
pattern <- pkgFileExt(type)

# get a list of all files in pkgPaths directory matching pattern
f <- list.files(path, pattern = pattern)
Expand All @@ -204,15 +196,19 @@ addOldPackage <- function(pkgs = NULL, path = NULL, vers = NULL,

if (length(f)) {
# if multiple versions present, always use latest
fp <- strsplit(f, "_") %>%
sapply(., `[[`, 1)

fv <- strsplit(f, "_") %>%
sapply(., `[[`, 2) %>%
strsplit(., pattern) %>%
sapply(., `[[`, 1) %>%
as.numeric_version()

fp <- local({
x <- strsplit(f, "_")
sapply(x, `[[`, 1)
})

fv <- local({
x <- strsplit(f, "_")
x <- sapply(x, `[[`, 2)
x <- strsplit(x, pattern)
x <- sapply(x, `[[`, 1)
as.numeric_version(x)
})

fout <- sapply(fp, function(x) {
ids.p <- which(fp %in% x)

Expand All @@ -221,11 +217,10 @@ addOldPackage <- function(pkgs = NULL, path = NULL, vers = NULL,
id.v <- which(fv == max(fv[ids.p]))

f[id.v]
}) %>% unique()

return(fout)
})
unique(fout)
} else {
return(character())
character()
}
}

Expand Down Expand Up @@ -326,5 +321,5 @@ addLocalPackage <- function(pkgs = NULL, pkgPath = NULL, path = NULL,
# write package index for each folder:
index <- updateRepoIndex(path = path, type = type, Rversion = Rversion)

return(invisible(index))
invisible(index)
}
6 changes: 3 additions & 3 deletions R/getCranDescription.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @importFrom XML readHTMLTable
oldGetCranDescription <- function(pkg, repos = getOption("repos"),
type = "source",
pkgs = pkgDep(pkg, repos = repos, type = type)){
pkgs = pkgDep(pkg, repos = repos, type = type)) {
getOne <- function(package) {
repos <- repos[[1]]
if(!grepl("/$", repos)) repos <- paste0(repos, "/")
Expand Down Expand Up @@ -42,9 +42,9 @@ oldGetCranDescription <- function(pkg, repos = getOption("repos"),
#' @example /inst/examples/example_getCranDescription.R
getCranDescription <- function(pkg, repos = getOption("repos"),
type = "source",
pkgs = pkgDep(pkg, repos = repos, type = type)){
pkgs = pkgDep(pkg, repos = repos, type = type)) {

if (getRversion() >= "3.4.1"){
if (getRversion() >= "3.4.1") {
pdb <- tools::CRAN_package_db()
pdb[match(pkgs, pdb$Package), ]
} else {
Expand Down
15 changes: 8 additions & 7 deletions R/github-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@ pkgFileExt <- function(type) {
}



getPkgVersFromFile <- function(file) {
file <- grep("\\.(tar\\.gz|zip|tgz)$", basename(as.character(file)), value = TRUE)
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)
pkg <- sapply(strsplit(file, "_"), "[[", 1)
vers <- sapply(strsplit(file, "_"), "[[", 2)
df <- data.frame(package = pkg, version = vers, stringsAsFactors = FALSE)
return(df[order(df$package),])
df <- data.frame(package = pkg, version = vers, stringsAsFactors = FALSE, row.names = NULL)
df <- df[order(df$package),]
row.names(df) <- seq_len(nrow(df))
df
} else {
return(NULL)
data.frame(package = character(0), version = character(0))
}
}



readDescription <- function(file) {
stopifnot(file.exists(file))
trimSpaces <- function(x){
trimSpaces <- function(x) {
gsub("^\\s+|\\s+$", "", x)
}

Expand Down Expand Up @@ -77,7 +78,7 @@ addPackageListing <- function(pdb = pkgAvail(), dcf, warnings = TRUE) {
# Possible to override the blocking of a package's (re-)installation after it has been required/loaded?

#' @importFrom httr GET stop_for_status content
readDescriptionGithub <- function(repo, username, branch = "master", quiet = TRUE){
readDescriptionGithub <- function(repo, username, branch = "master", quiet = TRUE) {
if (!missing(username) && !is.null(username)) repo <- paste(username, repo, sep = "/")
pkg <- sprintf("https://github.com/%s/raw/%s/DESCRIPTION", repo, branch)
ff <- tempfile()
Expand Down
16 changes: 7 additions & 9 deletions R/helpers.R → R/internal.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Get the path to the repo directory containing the package files.
#'
#'
#' @note Not all versions of R are compatible with with all package types (e.g., `mac.binary.el-capitan` is only valid for R > 3.4.0).
#'
#' @param Rversion Version of R. Can be specified as a character string with the two digit R version, e.g. "3.1". Defaults to [R.version]
Expand Down Expand Up @@ -45,13 +45,13 @@
#'
repoPrefix <- function(type, Rversion) {
Rversion <- twodigitRversion(Rversion)

if ((type == "mac.binary.el-capitan") && (numeric_version(Rversion) < "3.4")) {
warning("Type mac.binary.el-capitan only valid for R >= 3.4")
} else if ((type == "mac.binary.mavericks") && (numeric_version(Rversion) >= "3.4")) {
warning("Type mac.binary.mavericks only valid for R < 3.4")
}

switch(
type,
"source" = "src/contrib",
Expand All @@ -67,12 +67,10 @@ repoPrefix <- function(type, Rversion) {
#' Construct path to full binary location
#' @inheritParams makeRepo
#' @inheritParams repoPrefix
repoBinPath <- function(path, type, Rversion){
repoBinPath <- function(path, type, Rversion) {
normalizePath(file.path(path, repoPrefix(type, Rversion)), mustWork = FALSE, winslash = "/")
}



#' Get a two-digit version of the R version
#'
#' @param R Either a list of the format [R.version], a character string (e.g., `"3.1.2"`), or a numeric version of the type [R_system_version()].
Expand All @@ -81,12 +79,12 @@ repoBinPath <- function(path, type, Rversion){
#'
#' @importFrom methods is
#'
twodigitRversion <- function(R=R.version){
twodigitRversion <- function(R = R.version) {
if ("simple.list" %in% is(R)) {
paste(R$major, strsplit(R$minor, ".", fixed = TRUE)[[1L]][1L], sep = ".")
} else if ("R_system_version" %in% is(R)) {
paste(strsplit(as.character(R), ".", fixed=TRUE)[[1L]][1L:2L], collapse=".")
paste(strsplit(as.character(R), ".", fixed = TRUE)[[1L]][1L:2L], collapse = ".")
} else if (is.character(R)) {
paste(strsplit(R, ".", fixed=TRUE)[[1L]][1L:2L], collapse=".")
paste(strsplit(R, ".", fixed = TRUE)[[1L]][1L:2L], collapse = ".")
}
}
7 changes: 3 additions & 4 deletions R/makeDepGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fastdf <- function (list) {
list
}

addDepType <- function(p, type = c("Imports", "Depends", "LinkingTo", "Suggests"), pdb){
addDepType <- function(p, type = c("Imports", "Depends", "LinkingTo", "Suggests"), pdb) {
if (!p %in% rownames(pdb)) {
fastdf(list(
dep = character(0),
Expand Down Expand Up @@ -35,9 +35,9 @@ addDepType <- function(p, type = c("Imports", "Depends", "LinkingTo", "Suggests"
#' @importFrom igraph graph.data.frame
#' @export
#' @family dependency functions
#'
#'
#' @seealso [pkgDep()] to extract package dependencies
#'
#'
#' @example /inst/examples/example_makeDepGraph.R
makeDepGraph <- function(
pkg, availPkgs, repos = getOption("repos"), type = "source",
Expand Down Expand Up @@ -109,4 +109,3 @@ makeDepGraph <- function(
attr(ret, "pkgs") <- pkg_orig
ret
}

34 changes: 15 additions & 19 deletions R/makeRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@
#' @export
#' @family update repo functions
#'
#' @importFrom utils download.packages
#'
#' @example /inst/examples/example_makeRepo.R
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(t) {
pkgPath <- repoBinPath(path = path, type = t, Rversion = Rversion)
if(!file.exists(pkgPath)) {
if (!file.exists(pkgPath)) {
result <- dir.create(pkgPath, recursive = TRUE, showWarnings = FALSE)
if(result) {
if(!quiet) message("Created new folder: ", pkgPath)
if (result) {
if (!quiet) message("Created new folder: ", pkgPath)
} else {
stop("Unable to create repo path: ", pkgPath)
}
Expand All @@ -71,21 +73,21 @@ makeRepo <- function(pkgs, path, repos = getOption("repos"), type = "source",
pdb <- pkgAvail(repos = repos, type = t, Rversion = Rversion)

if (download) {
utils::download.packages(pkgs, destdir = pkgPath, available = pdb, repos = repos,
contriburl = contribUrl(repos, t, Rversion),
type = t, quiet = quiet)
download.packages(pkgs, destdir = pkgPath, available = pdb, repos = repos,
contriburl = contribUrl(repos, t, Rversion),
type = t, quiet = quiet)
}
})

if (download) {
downloaded <- downloaded[[1]][, 2]

## allow for more than one repo
fromLocalRepos <- grepl("^file://", repos)
if(any(fromLocalRepos)){

if (any(fromLocalRepos)) {
# need to copy files to correct folder
if (sum(fromLocalRepos) > 1)
if (sum(fromLocalRepos) > 1)
warning("More than one local repos provided. Only the first listed will be used.")
pat <- ifelse(Sys.info()["sysname"] == "Windows", "^file:///", "^file://")
repoPath <- gsub(pat, "", repos[fromLocalRepos][1])
Expand All @@ -110,10 +112,10 @@ updateRepoIndex <- function(path, type = "source", Rversion = R.version) {
n <- lapply(type, function(t) {
pkgPath <- repoBinPath(path = path, type = t, Rversion = Rversion)
if (grepl("mac.binary", t)) t <- "mac.binary"
tools::write_PACKAGES(dir = pkgPath, type = t)
write_packages(dir = pkgPath, type = t)
})
names(n) <- type
return(n)
n
}


Expand All @@ -122,14 +124,8 @@ updateRepoIndex <- function(path, type = "source", Rversion = R.version) {
#'
#' @inheritParams makeRepo
#' @export
makeLibrary <- function(pkgs, path, type = "source"){
makeLibrary <- function(pkgs, path, type = "source") {
.Deprecated("makeRepo")
NULL
# if(!file.exists(path)) stop("Download path does not exist")
# wd <- getwd()
# on.exit(setwd(wd))
# setwd(normalizePath(path))
# message(getwd())
# download.packages(pkgs, destdir = path, type = type)
}

Loading

0 comments on commit 77eace6

Please sign in to comment.