Skip to content

Commit

Permalink
Merge pull request #61 from RevolutionAnalytics/master
Browse files Browse the repository at this point in the history
Merge master into dev at v0.2.2
  • Loading branch information
andrie committed Mar 26, 2015
2 parents 1a9588c + 3acb9c9 commit 4d5b116
Show file tree
Hide file tree
Showing 23 changed files with 397 additions and 168 deletions.
11 changes: 7 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ Authors@R: c(person("Revolution Analytics", role="aut"), person("Andrie", "de
person("Alex", "Chubaty", role="ctb", email="[email protected]"))
License: GPL-2
Copyright: Revolution Analytics
Title: Create a mini Version of CRAN Containing Only Selected Packages
Title: Create a Mini Version of CRAN Containing Only Selected Packages
LazyData: true
LazyLoad: true
Description: Makes it possible to create an internally consistent
repository consisting of selected packages from CRAN-like repositories.
The user specifies a set of desired packages, and miniCRAN recursively
reads the dependency tree for these packages, then downloads only this
subset.
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 broadband access.
Version: 0.2.2
URL: https://github.com/RevolutionAnalytics/miniCRAN
BugReports: https://github.com/RevolutionAnalytics/miniCRAN/issues
Date: 2015-03-25
Date: 2015-03-26
Imports:
tools,
XML,
httr,
methods
methods,
utils
Suggests:
testthat(>= 0.9),
knitr,
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
miniCRAN v0.2-2 (Release date: 2015-03-25)
==============

Changes:
* Additional vignettes and documentation

miniCRAN v0.2-0 (Release date: 2014-12-16)
==============

Expand Down
6 changes: 4 additions & 2 deletions R/makeRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ makeRepo <- function(pkgs, path, repos=getOption("repos"), type="source",
}
}

pdb <- pkgAvail(repos = repos, type=type)
pdb <- pkgAvail(repos = repos, type=type, Rversion = Rversion)

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

Expand Down
46 changes: 42 additions & 4 deletions R/pkgDep.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ basePkgs <- function()names(which(installed.packages()[, "Priority"] == "base"))
#' @param enhances If TRUE, retrieves Enhances dependencies (non-recursively)
#'
#' @param includeBasePkgs If TRUE, include base R packages in results
#' @param Rversion Version of R. Can be specified as a character string with the two digit R version, e.g. "3.1". Defaults to \code{\link{R.version}}
#' @param ... Other arguments passed to \code{\link{available.packages}}
#'
#' @export
#' @family dependency functions
#'
#' @example /inst/examples/example_pkgDep.R

pkgDep <- function(pkg, availPkgs, repos=getOption("repos"), type="source", depends=TRUE, suggests=TRUE, enhances=FALSE, includeBasePkgs=FALSE, ...){
pkgDep <- function(pkg, availPkgs, repos=getOption("repos"), type="source", depends=TRUE, suggests=TRUE, enhances=FALSE, includeBasePkgs=FALSE, Rversion = R.version, ...){
if(!depends & !suggests & !enhances) {
warning("Returning nothing, since depends, suggests and enhances are all FALSE")
return(character(0))
Expand All @@ -49,7 +50,7 @@ pkgDep <- function(pkg, availPkgs, repos=getOption("repos"), type="source", depe
repos <- c(CRAN="http://cran.revolutionanalytics.com")
}
if(is.na(type)) type <- "source"
availPkgs <- pkgAvail(repos=repos, type=type, ...)
availPkgs <- pkgAvail(repos=repos, type=type, Rversion = Rversion, ...)
}
if(nrow(availPkgs) == 0){
stop("Unable to retrieve available packages from CRAN")
Expand Down Expand Up @@ -125,14 +126,51 @@ print.pkgDep <- function(x, ...){
#' @export
#' @family create repo functions
#' @seealso \code{\link{pkgDep}}
pkgAvail <- function(repos=getOption("repos"), type="source"){
pkgAvail <- function(repos=getOption("repos"), type="source", Rversion = R.version){
if(!grepl("^http://|file:///", repos[1]) && file.exists(repos[1])) {
repos <- paste0("file:///", normalizePath(repos[1], mustWork = FALSE, winslash = "/"))
} else {
if(!is.null(names(repos)) && repos["CRAN"] == "@CRAN@"){
repos <- c(CRAN="http://cran.revolutionanalytics.com")
}
}
available.packages(contrib.url(repos, type=type), type=type, filters=list())
utils::available.packages(contribUrl(repos, type=type, Rversion = Rversion), type=type, filters=list())
}


# Modified copy of utils::contrib.url()
contribUrl <- function (repos, type = getOption("pkgType"), Rversion = R.version) {
Rversion <- twodigitRversion(Rversion)
if (type == "both")
type <- "source"
if (type == "binary")
type <- .Platform$pkgType
if (is.null(repos))
return(NULL)
if ("@CRAN@" %in% repos && interactive()) {
cat(gettext("--- Please select a CRAN mirror for use in this session ---"),
"\n", sep = "")
flush.console()
chooseCRANmirror()
m <- match("@CRAN@", repos)
nm <- names(repos)
repos[m] <- getOption("repos")["CRAN"]
if (is.null(nm))
nm <- rep("", length(repos))
nm[m] <- "CRAN"
names(repos) <- nm
}
if ("@CRAN@" %in% repos)
stop("trying to use CRAN without setting a mirror")
ver <- Rversion
mac.path <- "macosx"
if (substr(type, 1L, 11L) == "mac.binary.") {
mac.path <- paste(mac.path, substring(type, 12L), sep = "/")
type <- "mac.binary"
}
res <- switch(type,
source = paste(gsub("/$", "", repos), "src", "contrib", sep = "/"),
mac.binary = paste(gsub("/$", "", repos), "bin", mac.path, "contrib", ver, sep = "/"),
win.binary = paste(gsub("/$", "", repos), "bin", "windows", "contrib", ver, sep = "/"))
res
}
34 changes: 10 additions & 24 deletions R/testSuiteFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,23 @@
}


# Use in unit tests to copy sample repo to path
# .copySampleRepo <- function(path){
# file.copy(
# from = list.dirs(system.file("inst/sample-repo", package="miniCRAN"), recursive = FALSE),
# to = path,
# recursive = TRUE
# )
# updateRepoIndex(path=path,
# type=c("source", "win.binary", "mac.binary.mavericks"),
# Rversion=list(major=3, minor=1))
# invisible(NULL)
# }


# Create sample repo from MRAN snapshot
.createSampleRepo <- function(MRAN, path, pkgs, Rversion=list(major=3, minor=1)){
.createSampleRepo <- function(MRAN, path, pkgs, Rversion="3.1"){
if(missing(MRAN)) MRAN <- c(CRAN="http://mran.revolutionanalytics.com/snapshot/2014-10-15")
if(missing(path)) path <- file.path(tempdir(), "miniCRAN", Sys.Date())
if(missing(pkgs)) pkgs <- c("chron", "adaptivetau")

pdb_source <- pkgAvail(repos=MRAN, type="source")
pdb_win <- pkgAvail(repos=MRAN, type="win.binary")
pdb_mac <- pkgAvail(repos=MRAN, type="mac.binary.mavericks")
pdb_source <- pkgAvail(repos=MRAN, type="source", Rversion = Rversion)
pdb_win <- pkgAvail(repos=MRAN, type="win.binary", Rversion = Rversion)
pdb_mac <- pkgAvail(repos=MRAN, type="mac.binary", Rversion = Rversion)


pkgList_source <- pkgDep(pkgs, availPkgs=pdb_source, repos=MRAN, type="source", suggests=FALSE)
makeRepo(pkgList_source, path=path, repos=MRAN, type="source", quiet=TRUE)
pkgList_source <- pkgDep(pkgs, availPkgs=pdb_source, repos=MRAN, type="source", suggests=FALSE, Rversion = Rversion)
makeRepo(pkgList_source, path=path, repos=MRAN, type="source", quiet=TRUE, Rversion = Rversion)

pkgList_win <- pkgDep(pkgs, availPkgs=pdb_win, repos=MRAN, type="win.binary", suggests=FALSE)
makeRepo(pkgList_win, path=path, repos=MRAN, type="win.binary", quiet=TRUE)
pkgList_win <- pkgDep(pkgs, availPkgs=pdb_win, repos=MRAN, type="win.binary", suggests=FALSE, Rversion = Rversion)
makeRepo(pkgList_win, path=path, repos=MRAN, type="win.binary", quiet=TRUE, Rversion = Rversion)

pkgList_mac <- pkgDep(pkgs, availPkgs=pdb_mac, repos=MRAN, type="mac.binary.mavericks", suggests=FALSE)
makeRepo(pkgList_mac, path=path, repos=MRAN, type="mac.binary.mavericks", quiet=TRUE)
pkgList_mac <- pkgDep(pkgs, availPkgs=pdb_mac, repos=MRAN, type="mac.binary", suggests=FALSE, Rversion = Rversion)
makeRepo(pkgList_mac, path=path, repos=MRAN, type="mac.binary", quiet=TRUE, Rversion = Rversion)
}
19 changes: 11 additions & 8 deletions R/updatePackages.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
#'
#' @example /inst/examples/example_updatePackages.R
#'
oldPackages <- function (path=NULL, repos=getOption("repos"),
availPkgs=pkgAvail(repos=repos, type=type),
method, availableLocal=pkgAvail(repos=path, type=type), type="source",
Rversion=R.version) {
oldPackages <- function (path = NULL,
repos = getOption("repos"),
availPkgs = pkgAvail(repos=repos, type=type, Rversion=Rversion),
method,
availableLocal = pkgAvail(repos=path, type=type, Rversion=Rversion), type="source",
Rversion = R.version) {
if (is.null(path)) stop("path to miniCRAN repo must be specified")
if (!missing(availPkgs)) {
if (!is.matrix(availPkgs) || !is.character(availPkgs[, "Package"]))
Expand Down Expand Up @@ -64,13 +66,14 @@ oldPackages <- function (path=NULL, repos=getOption("repos"),
#' @export
#'
updatePackages <- function (path=NULL, repos=getOption("repos"),
method, ask=TRUE, availPkgs=pkgAvail(repos=repos, type=type),
method, ask=TRUE,
availPkgs=pkgAvail(repos=repos, type=type, Rversion=Rversion),
oldPkgs=NULL, type="source",
Rversion=getRversion(),
Rversion=R.version,
quiet=FALSE) {
force(ask)
simplifyRepos <- function(repos, type) {
tail <- substring(contrib.url("---", type), 4)
tail <- substring(contribUrl("---", type=type, Rversion=Rversion), 4)
ind <- regexpr(tail, repos, fixed=TRUE)
ind <- ifelse(ind > 0, ind-1, nchar(repos, type="c"))
substr(repos, 1, ind)
Expand Down Expand Up @@ -129,6 +132,6 @@ updatePackages <- function (path=NULL, repos=getOption("repos"),
oldPkgs
}
if (length(update[,"Package"])) {
addPackage(update[,"Package"], path=path, repos=repos, type=type, quiet=quiet, deps=FALSE)
addPackage(update[,"Package"], path=path, repos=repos, type=type, quiet=quiet, deps=FALSE, Rversion=Rversion)
}
}
2 changes: 1 addition & 1 deletion inst/doc/miniCRAN-dependency-graph.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## ----init----------------------------------------------------------------
library(miniCRAN)
library("miniCRAN")

## ----pkgdep--------------------------------------------------------------
tags <- "chron"
Expand Down
Loading

0 comments on commit 4d5b116

Please sign in to comment.