Skip to content

Commit

Permalink
add MRAN url as package option (close #72)
Browse files Browse the repository at this point in the history
Note: use http instead of https for R < 3.2.2
  • Loading branch information
achubaty committed Aug 11, 2017
1 parent aeda340 commit d521aa6
Show file tree
Hide file tree
Showing 26 changed files with 130 additions and 103 deletions.
10 changes: 5 additions & 5 deletions R/MRAN.R
Original file line number Diff line number Diff line change
@@ -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]
22 changes: 10 additions & 12 deletions R/getCranDescription.R
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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)
}
}


57 changes: 31 additions & 26 deletions R/minicran-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -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()
}
8 changes: 4 additions & 4 deletions inst/examples/example_addPackageListingGithub.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion inst/examples/example_checkVersions.R
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
4 changes: 2 additions & 2 deletions inst/examples/example_getCranDescription.R
Original file line number Diff line number Diff line change
@@ -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"))
)
}
10 changes: 5 additions & 5 deletions inst/examples/example_makeDepGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ availPkgs <- cranJuly2014

\dontrun{
availPkgs <- pkgAvail(
repos = c(CRAN = "http://mran.microsoft.com"),
repos = c(CRAN = getOption("minicran.mran")),
type = "source"
)
}


# Create dependency graph using stored database of available packages
p <- makeDepGraph(
c("ggplot2", "forecast"),
c("ggplot2", "forecast"),
availPkgs = availPkgs
)

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions inst/examples/example_makeRepo.R
Original file line number Diff line number Diff line change
@@ -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"
)
}
Expand Down
6 changes: 3 additions & 3 deletions inst/examples/example_pkgDep.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 5 additions & 5 deletions inst/examples/example_plot.pkgDepGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ pdb <- cranJuly2014

\dontrun{
pdb <- pkgAvail(
repos = c(CRAN = "http://mran.microsoft.com"),
repos = c(CRAN = getOption("minicran.mran")),
type = "source"
)
}

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)

2 changes: 1 addition & 1 deletion inst/examples/example_rsynctools.R
Original file line number Diff line number Diff line change
@@ -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")))
}
2 changes: 1 addition & 1 deletion inst/examples/example_updatePackages.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion man/addOldPackage.Rd

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

2 changes: 1 addition & 1 deletion man/addPackage.Rd

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

8 changes: 4 additions & 4 deletions man/addPackageListingGithub.Rd

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

2 changes: 1 addition & 1 deletion man/checkVersions.Rd

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

4 changes: 2 additions & 2 deletions man/getCranDescription.Rd

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

Loading

0 comments on commit d521aa6

Please sign in to comment.