diff --git a/R/MRAN.R b/R/MRAN.R index aba929c..c4aab4c 100644 --- a/R/MRAN.R +++ b/R/MRAN.R @@ -1,9 +1,9 @@ -MRAN <- function(snapshot){ - url <- "https://mran.microsoft.com" - if(missing("snapshot") || is.null(snapshot)){ - url +MRAN <- function(snapshot) { + url <- getOption("minicran.mran") + if (missing("snapshot") || is.null(snapshot)) { + url } else { sprintf("%s/snapshot/%s", url, snapshot) } } -CRAN <- function()getOption("repos")[1] +CRAN <- function() getOption("repos")[1] diff --git a/R/getCranDescription.R b/R/getCranDescription.R index d55bef1..bb8e34d 100644 --- a/R/getCranDescription.R +++ b/R/getCranDescription.R @@ -1,13 +1,13 @@ #' @importFrom XML readHTMLTable -oldGetCranDescription <- function(pkg, repos = getOption("repos"), - type = "source", +oldGetCranDescription <- function(pkg, repos = getOption("repos"), + type = "source", pkgs = pkgDep(pkg, repos = repos, type = type)){ getOne <- function(package) { repos <- repos[[1]] if(!grepl("/$", repos)) repos <- paste0(repos, "/") - - url <- gsub("https://", "http://", + + url <- gsub("https://", "http://", sprintf("%sweb/packages/%s/index.html", repos, package) ) x <- tryCatch({ @@ -36,20 +36,18 @@ oldGetCranDescription <- function(pkg, repos = getOption("repos"), #' #' @inheritParams pkgDep #' @inheritParams makeRepo -#' +#' #' @export -#' +#' #' @example /inst/examples/example_getCranDescription.R -getCranDescription <- function(pkg, repos = getOption("repos"), - type = "source", +getCranDescription <- function(pkg, repos = getOption("repos"), + type = "source", 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 { oldGetCranDescription(pkg = pkg, repos = repos, type = type, pkgs = pkgs) } } - - diff --git a/R/minicran-package.R b/R/minicran-package.R index 805012b..c3e4f99 100644 --- a/R/minicran-package.R +++ b/R/minicran-package.R @@ -7,53 +7,58 @@ #' #'@description #' -#' At the end of 2014, CRAN consisted of more than 6,000 packages. Many organisations need to maintain a private mirror of CRAN, but with only a subset of packages that are relevant to them. -#' -#' `miniCRAN` 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. -#' -#' +#' At the end of 2014, CRAN consisted of more than 6,000 packages. Many organisations need to maintain a private mirror of CRAN, but with only a subset of packages that are relevant to them. +#' +#' `miniCRAN` 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. +#' +#' #' There are many reasons for not creating a complete mirror CRAN using `rsync`: #' #' * You may wish to mirror only a subset of CRAN, for security, legal compliance or any other in-house reason #' * You may wish to restrict internal package use to a subset of public packages, to minimize package duplication, or other reasons of coding standards #' * You may wish to make packages available from public repositories other than CRAN, e.g. BioConductor, r-forge, OmegaHat, etc. #' * You may wish to add custom in-house packages to your repository -#' +#' #' The ambition of `miniCRAN` is to eventually satisfy all of these considerations. -#' +#' #' @section Making a private repo: -#' +#' #' * [pkgAvail()]: Read from a local (or remote) CRAN-like repository and determine available packages. #' * [pkgDep()]: Find (recursive) package dependencies. #' * [makeRepo()] : Make a mini CRAN repository, by downloading packages (and their dependencies) and creating the appropriate file structure for a repository. This allows you to use functions like [utils::available.packages()] and [utils::install.packages()] on your local repository. -#' +#' #' This subset will be internally consistent, i.e. the following functions will work as expected: #' * [utils::available.packages()] #' * [utils::install.packages()] -#' +#' #' The main function is [makeRepo()] - this will download all the required packages, with their dependencies, into the appropriate repository file structure, and then create the repository index (PACKAGES) file. -#' -#' -#' +#' +#' +#' #' @section Updating packages in a repo: -#' +#' #' * [oldPackages()]: Indicates packages which have a (suitable) later version on the repositories #' * [updatePackages()]: Offers to download and install such packages -#' -#' -#' +#' +#' +#' #' @section Creating dependencies: -#' +#' #' To get a recursive list of dependencies as well as a plot, use [pkgDep()] followed by [makeDepGraph()]. -#' +#' #' * [pkgDep()]: Find (recursive) package dependencies. #' * [makeDepGraph()]: Create graph of selected package dependencies. #' * [plot.pkgDepGraph()]: Create a visualization of the dependency graph -#' -#' -#' -#' -#' +#' +#' +#' +#' @section Package options: +#' +#' \describe{ +#' \item{\code{minicran.mran}}{preferred MRAN URL. Defaults to \url{https://mran.microsoft.com} +#' for R versions 3.2.2 and greater. Versions earlier than 3.2.2 use HTTP instead of HTTPS.} +#' } +#' #' @name miniCRAN-package #' @aliases miniCRAN minicran #' @docType package @@ -69,9 +74,9 @@ NULL # data documentation ------------------------------------------------------ #' Stored version of available.packages() -#' +#' #' Copy of the result of [utils::available.packages()] on July 1, 2014. -#' +#' #' @docType data #' @keywords datasets #' @name cranJuly2014 diff --git a/R/zzz.R b/R/zzz.R index fedb65a..77d760e 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,2 +1,20 @@ # globals <- new.env(parent=emptyenv(), hash=TRUE) # globals$have_RCurl <- require("RCurl") + +.onLoad <- function(libname, pkgname) { + mran.url <- if (getRversion() >= "3.2.2") { + "https://mran.microsoft.com" ## use HTTPS + } else { + "http://mran.microsoft.com" ## use HTTP + } + + ## set options using the approach used by devtools + opts <- options() + opts.miniCRAN <- list( + minicran.mran = mran.url + ) + toset <- !(names(opts.miniCRAN) %in% names(opts)) + if (any(toset)) options(opts.miniCRAN[toset]) + + invisible() +} diff --git a/inst/examples/example_addPackageListingGithub.R b/inst/examples/example_addPackageListingGithub.R index a1d7fa3..bc9671e 100644 --- a/inst/examples/example_addPackageListingGithub.R +++ b/inst/examples/example_addPackageListingGithub.R @@ -2,16 +2,16 @@ pdb <- cranJuly2014 \dontrun{ - pdb <- pkgAvail(repos = c(CRAN = "http://mran.microsoft.com")) - + pdb <- pkgAvail(repos = c(CRAN = getOption("minicran.mran"))) + # Overwrite pdb with development version of miniCRAN at github newpdb <- addPackageListingGithub(pdb = pdb, "andrie/miniCRAN") newpdb["miniCRAN", ] - + # Add package from github that's not currently on CRAN newpdb <- addPackageListingGithub(pdb = pdb, repo = "RevolutionAnalytics/checkpoint") newpdb["checkpoint", ] - + set.seed(1) plot(makeDepGraph("checkpoint", availPkgs = newpdb, suggests = TRUE)) } diff --git a/inst/examples/example_checkVersions.R b/inst/examples/example_checkVersions.R index e36c4f0..77a45a1 100644 --- a/inst/examples/example_checkVersions.R +++ b/inst/examples/example_checkVersions.R @@ -1,7 +1,7 @@ ### `checkVersions` and `add.packages.miniCRAN` require an existing miniCRAN repo # Specify list of packages to download -revolution <- c(CRAN = "http://mran.microsoft.com") +revolution <- c(CRAN = getOption("miniCRAN.mran")) pkgs <- c("foreach") pkgTypes <- c("source", "win.binary") diff --git a/inst/examples/example_getCranDescription.R b/inst/examples/example_getCranDescription.R index a4cd812..2c3a4ff 100644 --- a/inst/examples/example_getCranDescription.R +++ b/inst/examples/example_getCranDescription.R @@ -1,5 +1,5 @@ \dontrun{ -getCranDescription(c("igraph", "ggplot2", "XML"), - repos = c(CRAN = "http://mran.microsoft.com") +getCranDescription(c("igraph", "ggplot2", "XML"), + repos = c(CRAN = getOption("minicran.mran")) ) } diff --git a/inst/examples/example_makeDepGraph.R b/inst/examples/example_makeDepGraph.R index 8f3d3e6..39f4a4b 100644 --- a/inst/examples/example_makeDepGraph.R +++ b/inst/examples/example_makeDepGraph.R @@ -5,7 +5,7 @@ availPkgs <- cranJuly2014 \dontrun{ availPkgs <- pkgAvail( - repos = c(CRAN = "http://mran.microsoft.com"), + repos = c(CRAN = getOption("minicran.mran")), type = "source" ) } @@ -13,7 +13,7 @@ availPkgs <- pkgAvail( # Create dependency graph using stored database of available packages p <- makeDepGraph( - c("ggplot2", "forecast"), + c("ggplot2", "forecast"), availPkgs = availPkgs ) @@ -23,10 +23,10 @@ if(require(igraph)) plot(p) \dontrun{ # Create dependency graph using newly retrieved database from CRAN - + p <- makeDepGraph( - c("ggplot2", "forecast"), - repos = c(CRAN = "http://mran.microsoft.com"), + c("ggplot2", "forecast"), + repos = c(CRAN = getOption("minicran.mran")), type = "source" ) if(require(igraph)) plot(p) diff --git a/inst/examples/example_makeRepo.R b/inst/examples/example_makeRepo.R index a053b6b..1f8a2df 100644 --- a/inst/examples/example_makeRepo.R +++ b/inst/examples/example_makeRepo.R @@ -1,13 +1,13 @@ # Specify list of packages to download -revolution <- c(CRAN = "http://mran.microsoft.com") +revolution <- c(CRAN = getOption("minicran.mran")) pkgs <- c("foreach") pdb <- cranJuly2014 \dontrun{ pdb <- pkgAvail( - repos = c(CRAN = "http://mran.microsoft.com"), + repos = c(CRAN = getOption("minicran.mran")), type = "source" ) } diff --git a/inst/examples/example_pkgDep.R b/inst/examples/example_pkgDep.R index e177563..23c1550 100644 --- a/inst/examples/example_pkgDep.R +++ b/inst/examples/example_pkgDep.R @@ -1,13 +1,13 @@ \dontrun{ -pkgDep(pkg = c("ggplot2", "plyr", "reshape2"), - repos = c(CRAN = "http://mran.microsoft.com") +pkgDep(pkg = c("ggplot2", "plyr", "reshape2"), + repos = c(CRAN = getOption("minicran.mran")) ) } pdb <- cranJuly2014 \dontrun{ -pdb <- pkgAvail(repos = c(CRAN = "http://mran.microsoft.com")) +pdb <- pkgAvail(repos = c(CRAN = getOption("minicran.mran"))) } pkgDep(pkg = c("ggplot2", "plyr", "reshape2"), pdb) diff --git a/inst/examples/example_plot.pkgDepGraph.R b/inst/examples/example_plot.pkgDepGraph.R index e89a992..c1616a7 100644 --- a/inst/examples/example_plot.pkgDepGraph.R +++ b/inst/examples/example_plot.pkgDepGraph.R @@ -5,7 +5,7 @@ pdb <- cranJuly2014 \dontrun{ pdb <- pkgAvail( - repos = c(CRAN = "http://mran.microsoft.com"), + repos = c(CRAN = getOption("minicran.mran")), type = "source" ) } @@ -13,19 +13,19 @@ pdb <- cranJuly2014 dg <- makeDepGraph(tags, availPkgs = pdb , includeBasePkgs = FALSE, suggests = TRUE, enhances = TRUE) -set.seed(42); +set.seed(42); plot(dg) # Move edge legend to top left -set.seed(42); +set.seed(42); plot(dg, legendPosition = c(-1, 1)) # Change font size and shape size -set.seed(42); +set.seed(42); plot(dg, legendPosition = c(-1, 1), vertex.size = 20, cex = 0.5) # Move vertex legend to top right -set.seed(42); +set.seed(42); plot(dg, legendPosition = c(1, 1), vertex.size = 20, cex = 0.5) diff --git a/inst/examples/example_rsynctools.R b/inst/examples/example_rsynctools.R index d347487..f30e95a 100644 --- a/inst/examples/example_rsynctools.R +++ b/inst/examples/example_rsynctools.R @@ -1,4 +1,4 @@ \dontrun{ pkgs <- c("ggplot2", "plyr", "reshape2") - makeRsyncInclude(pkgs, type = "source", repos = c(CRAN = "http://mran.microsoft.com")) + makeRsyncInclude(pkgs, type = "source", repos = c(CRAN = getOption("minicran.mran"))) } diff --git a/inst/examples/example_updatePackages.R b/inst/examples/example_updatePackages.R index 1d9fdb1..8f1e311 100644 --- a/inst/examples/example_updatePackages.R +++ b/inst/examples/example_updatePackages.R @@ -1,7 +1,7 @@ ### `oldPackages` and `updatePackages` require an existing miniCRAN repo # Specify list of packages to download -revolution <- c(CRAN = "http://mran.microsoft.com") +revolution <- c(CRAN = getOption("minicran.mran")) pkgs <- c("foreach") pdb <- cranJuly2014 diff --git a/man/addOldPackage.Rd b/man/addOldPackage.Rd index 010a607..ae3bbd0 100644 --- a/man/addOldPackage.Rd +++ b/man/addOldPackage.Rd @@ -40,7 +40,7 @@ Dependencies for old package versions cannot be determined automatically and mus ### `checkVersions` and `add.packages.miniCRAN` require an existing miniCRAN repo # Specify list of packages to download -revolution <- c(CRAN = "http://mran.microsoft.com") +revolution <- c(CRAN = getOption("miniCRAN.mran")) pkgs <- c("foreach") pkgTypes <- c("source", "win.binary") diff --git a/man/addPackage.Rd b/man/addPackage.Rd index c79587c..fdbd53e 100644 --- a/man/addPackage.Rd +++ b/man/addPackage.Rd @@ -35,7 +35,7 @@ Add packages to a miniCRAN repository. ### `checkVersions` and `add.packages.miniCRAN` require an existing miniCRAN repo # Specify list of packages to download -revolution <- c(CRAN = "http://mran.microsoft.com") +revolution <- c(CRAN = getOption("miniCRAN.mran")) pkgs <- c("foreach") pkgTypes <- c("source", "win.binary") diff --git a/man/addPackageListingGithub.Rd b/man/addPackageListingGithub.Rd index 8edb53d..bfbf12b 100644 --- a/man/addPackageListingGithub.Rd +++ b/man/addPackageListingGithub.Rd @@ -24,16 +24,16 @@ Downloads the DESCRIPTION file from a package on github, parses the fields and a pdb <- cranJuly2014 \dontrun{ - pdb <- pkgAvail(repos = c(CRAN = "http://mran.microsoft.com")) - + pdb <- pkgAvail(repos = c(CRAN = getOption("minicran.mran"))) + # Overwrite pdb with development version of miniCRAN at github newpdb <- addPackageListingGithub(pdb = pdb, "andrie/miniCRAN") newpdb["miniCRAN", ] - + # Add package from github that's not currently on CRAN newpdb <- addPackageListingGithub(pdb = pdb, repo = "RevolutionAnalytics/checkpoint") newpdb["checkpoint", ] - + set.seed(1) plot(makeDepGraph("checkpoint", availPkgs = newpdb, suggests = TRUE)) } diff --git a/man/checkVersions.Rd b/man/checkVersions.Rd index 4af2670..158ef2d 100644 --- a/man/checkVersions.Rd +++ b/man/checkVersions.Rd @@ -26,7 +26,7 @@ Checks for previous versions, and returns the file paths for packages with multi ### `checkVersions` and `add.packages.miniCRAN` require an existing miniCRAN repo # Specify list of packages to download -revolution <- c(CRAN = "http://mran.microsoft.com") +revolution <- c(CRAN = getOption("miniCRAN.mran")) pkgs <- c("foreach") pkgTypes <- c("source", "win.binary") diff --git a/man/getCranDescription.Rd b/man/getCranDescription.Rd index c8e139d..71612a9 100644 --- a/man/getCranDescription.Rd +++ b/man/getCranDescription.Rd @@ -21,8 +21,8 @@ Scrape DESCRIPTION from CRAN for each pkg. } \examples{ \dontrun{ -getCranDescription(c("igraph", "ggplot2", "XML"), - repos = c(CRAN = "http://mran.microsoft.com") +getCranDescription(c("igraph", "ggplot2", "XML"), + repos = c(CRAN = getOption("minicran.mran")) ) } } diff --git a/man/makeDepGraph.Rd b/man/makeDepGraph.Rd index bee10bc..580764e 100644 --- a/man/makeDepGraph.Rd +++ b/man/makeDepGraph.Rd @@ -35,7 +35,7 @@ availPkgs <- cranJuly2014 \dontrun{ availPkgs <- pkgAvail( - repos = c(CRAN = "http://mran.microsoft.com"), + repos = c(CRAN = getOption("minicran.mran")), type = "source" ) } @@ -43,7 +43,7 @@ availPkgs <- pkgAvail( # Create dependency graph using stored database of available packages p <- makeDepGraph( - c("ggplot2", "forecast"), + c("ggplot2", "forecast"), availPkgs = availPkgs ) @@ -53,10 +53,10 @@ if(require(igraph)) plot(p) \dontrun{ # Create dependency graph using newly retrieved database from CRAN - + p <- makeDepGraph( - c("ggplot2", "forecast"), - repos = c(CRAN = "http://mran.microsoft.com"), + c("ggplot2", "forecast"), + repos = c(CRAN = getOption("minicran.mran")), type = "source" ) if(require(igraph)) plot(p) diff --git a/man/makeRepo.Rd b/man/makeRepo.Rd index 77df776..7fff26f 100644 --- a/man/makeRepo.Rd +++ b/man/makeRepo.Rd @@ -70,14 +70,14 @@ The folder structure of a repository \examples{ # Specify list of packages to download -revolution <- c(CRAN = "http://mran.microsoft.com") +revolution <- c(CRAN = getOption("minicran.mran")) pkgs <- c("foreach") pdb <- cranJuly2014 \dontrun{ pdb <- pkgAvail( - repos = c(CRAN = "http://mran.microsoft.com"), + repos = c(CRAN = getOption("minicran.mran")), type = "source" ) } diff --git a/man/miniCRAN-package.Rd b/man/miniCRAN-package.Rd index ef95e7d..49d8590 100644 --- a/man/miniCRAN-package.Rd +++ b/man/miniCRAN-package.Rd @@ -57,6 +57,15 @@ To get a recursive list of dependencies as well as a plot, use \code{\link[=pkgD } } +\section{Package options}{ + + +\describe{ +\item{\code{minicran.mran}}{preferred MRAN URL. Defaults to \url{https://mran.microsoft.com} +for R versions 3.2.2 and greater. Versions earlier than 3.2.2 use HTTP instead of HTTPS.} +} +} + \author{ Andrie de Vries \email{adevries@microsoft.com} with contributions from Alex Chubaty \email{alex.chubaty@gmail.com} } diff --git a/man/pkgDep.Rd b/man/pkgDep.Rd index ff2a6fc..b02ee3b 100644 --- a/man/pkgDep.Rd +++ b/man/pkgDep.Rd @@ -37,14 +37,14 @@ Performs recursive retrieve for \code{Depends}, \code{Imports} and \code{LinkLib \examples{ \dontrun{ -pkgDep(pkg = c("ggplot2", "plyr", "reshape2"), - repos = c(CRAN = "http://mran.microsoft.com") +pkgDep(pkg = c("ggplot2", "plyr", "reshape2"), + repos = c(CRAN = getOption("minicran.mran")) ) } pdb <- cranJuly2014 \dontrun{ -pdb <- pkgAvail(repos = c(CRAN = "http://mran.microsoft.com")) +pdb <- pkgAvail(repos = c(CRAN = getOption("minicran.mran"))) } pkgDep(pkg = c("ggplot2", "plyr", "reshape2"), pdb) diff --git a/man/plot.pkgDepGraph.Rd b/man/plot.pkgDepGraph.Rd index 0fa6e97..7826eb0 100644 --- a/man/plot.pkgDepGraph.Rd +++ b/man/plot.pkgDepGraph.Rd @@ -36,7 +36,7 @@ pdb <- cranJuly2014 \dontrun{ pdb <- pkgAvail( - repos = c(CRAN = "http://mran.microsoft.com"), + repos = c(CRAN = getOption("minicran.mran")), type = "source" ) } @@ -44,20 +44,20 @@ pdb <- cranJuly2014 dg <- makeDepGraph(tags, availPkgs = pdb , includeBasePkgs = FALSE, suggests = TRUE, enhances = TRUE) -set.seed(42); +set.seed(42); plot(dg) # Move edge legend to top left -set.seed(42); +set.seed(42); plot(dg, legendPosition = c(-1, 1)) # Change font size and shape size -set.seed(42); +set.seed(42); plot(dg, legendPosition = c(-1, 1), vertex.size = 20, cex = 0.5) # Move vertex legend to top right -set.seed(42); +set.seed(42); plot(dg, legendPosition = c(1, 1), vertex.size = 20, cex = 0.5) } diff --git a/man/updatePackages.Rd b/man/updatePackages.Rd index 3826046..6bff031 100644 --- a/man/updatePackages.Rd +++ b/man/updatePackages.Rd @@ -53,7 +53,7 @@ These functions are based on \code{\link[=update.packages]{update.packages()}}. ### `oldPackages` and `updatePackages` require an existing miniCRAN repo # Specify list of packages to download -revolution <- c(CRAN = "http://mran.microsoft.com") +revolution <- c(CRAN = getOption("minicran.mran")) pkgs <- c("foreach") pdb <- cranJuly2014 diff --git a/tests/testthat/test-6-getCranDescription.R b/tests/testthat/test-6-getCranDescription.R index 94b409b..7e5606c 100644 --- a/tests/testthat/test-6-getCranDescription.R +++ b/tests/testthat/test-6-getCranDescription.R @@ -1,12 +1,10 @@ -if(interactive()) library(testthat) +if (interactive()) library(testthat) context("get CRAN description") test_that("can read CRAN description", { - + skip_on_cran() - p <- getCranDescription("miniCRAN", repos = c(CRAN = "https://mran.microsoft.com")) + p <- getCranDescription("miniCRAN", repos = c(CRAN = getOption("minicran.mran"))) expect_is(p, "data.frame") expect_equal(p$Package[1], "miniCRAN") - }) - diff --git a/tests/testthat/test-7-addGithubPackage.R b/tests/testthat/test-7-addGithubPackage.R index 10eca95..4135f96 100644 --- a/tests/testthat/test-7-addGithubPackage.R +++ b/tests/testthat/test-7-addGithubPackage.R @@ -1,13 +1,13 @@ -if(interactive()) library(testthat) +if (interactive()) library(testthat) context("pkgDep") test_that("can add package from github",{ - + skip_on_cran() - pdb <- pkgAvail(repos = c(CRAN = "http://mran.microsoft.com")) + pdb <- pkgAvail(repos = c(CRAN = getOption("minicran.mran"))) expect_is(pdb, "matrix") - + # Overwrite pdb with development version of miniCRAN at github expect_warning( newpdb <- addPackageListingGithub(pdb = pdb, "andrie/miniCRAN"), @@ -16,5 +16,4 @@ test_that("can add package from github",{ expect_is(newpdb, "matrix") expect_equal(nrow(pdb), nrow(newpdb)) expect_equal(ncol(pdb), ncol(newpdb)) - -}) \ No newline at end of file +})