From 0568751e8d6cd9b663ccafb4cbad9acc106247e3 Mon Sep 17 00:00:00 2001 From: Andrie de Vries Date: Tue, 26 Dec 2017 20:33:05 +0000 Subject: [PATCH] Rebuild vignettes --- vignettes/miniCRAN-dependency-graph.R | 20 +++ vignettes/miniCRAN-dependency-graph.html | 155 +++++++++++++++++++ vignettes/miniCRAN-introduction.R | 80 ++++++++++ vignettes/miniCRAN-introduction.html | 181 +++++++++++++++++++++++ vignettes/miniCRAN-non-CRAN-repos.R | 39 +++++ vignettes/miniCRAN-non-CRAN-repos.html | 138 +++++++++++++++++ 6 files changed, 613 insertions(+) create mode 100644 vignettes/miniCRAN-dependency-graph.R create mode 100644 vignettes/miniCRAN-dependency-graph.html create mode 100644 vignettes/miniCRAN-introduction.R create mode 100644 vignettes/miniCRAN-introduction.html create mode 100644 vignettes/miniCRAN-non-CRAN-repos.R create mode 100644 vignettes/miniCRAN-non-CRAN-repos.html diff --git a/vignettes/miniCRAN-dependency-graph.R b/vignettes/miniCRAN-dependency-graph.R new file mode 100644 index 0000000..115e61e --- /dev/null +++ b/vignettes/miniCRAN-dependency-graph.R @@ -0,0 +1,20 @@ +## ----init---------------------------------------------------------------- +library("miniCRAN") + +## ----pkgdep-------------------------------------------------------------- +tags <- "chron" +pkgDep(tags, availPkgs = cranJuly2014) + +## ----makeDepGraph, warning=FALSE----------------------------------------- +dg <- makeDepGraph(tags, enhances = TRUE, availPkgs = cranJuly2014) +set.seed(1) +plot(dg, legendPosition = c(-1, 1), vertex.size = 20) + +## ----so-tags, warning=FALSE, fig.width=10, fig.height=10----------------- +tags <- c("ggplot2", "data.table", "plyr", "knitr", "shiny", "xts", "lattice") +pkgDep(tags, suggests = TRUE, enhances = FALSE, availPkgs = cranJuly2014) + +dg <- makeDepGraph(tags, enhances = TRUE, availPkgs = cranJuly2014) +set.seed(1) +plot(dg, legendPosition = c(-1, -1), vertex.size = 10, cex = 0.7) + diff --git a/vignettes/miniCRAN-dependency-graph.html b/vignettes/miniCRAN-dependency-graph.html new file mode 100644 index 0000000..46b794c --- /dev/null +++ b/vignettes/miniCRAN-dependency-graph.html @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + +Using miniCRAN to identify package dependencies + + + + + + + + + + + + + + + + + +

Using miniCRAN to identify package dependencies

+

Andrie de Vries

+

December 26, 2017

+ + + +

The miniCRAN package exposes two functions that provide information about dependencies:

+ +

The package chron neatly illustrates the different roles of Imports, Suggests and Enhances:

+ +
+

A worked example using the package chron

+

The function pkgDep() exposes not only these dependencies, but also all recursive dependencies. In other words, it answers the question which packages need to be installed to satisfy all dependencies of dependencies.

+

This means that the algorithm is as follows:

+ +

The resulting list of packages should then contain the complete list necessary to satisfy all dependencies. In code:

+
library("miniCRAN")
+
tags <- "chron"
+pkgDep(tags, availPkgs = cranJuly2014)
+
##  [1] "chron"        "RColorBrewer" "dichromat"    "munsell"     
+##  [5] "plyr"         "labeling"     "colorspace"   "Rcpp"        
+##  [9] "digest"       "gtable"       "reshape2"     "scales"      
+## [13] "proto"        "MASS"         "stringr"      "ggplot2"
+

To create an igraph plot of the dependencies, use the function makeDepGraph() and plot the results:

+
dg <- makeDepGraph(tags, enhances = TRUE, availPkgs = cranJuly2014)
+set.seed(1)
+plot(dg, legendPosition = c(-1, 1), vertex.size = 20)
+

+

Note how the dependencies expand to zoo (enhanced), scales and ggplot (suggested) and then recursively from there to get all the Imports and LinkingTo dependencies.

+
+
+

An example with multiple input packages

+

As a final example, create a dependency graph of seven very popular R packages:

+
tags <- c("ggplot2", "data.table", "plyr", "knitr", "shiny", "xts", "lattice")
+pkgDep(tags, suggests = TRUE, enhances = FALSE, availPkgs = cranJuly2014)
+
##  [1] "ggplot2"      "data.table"   "plyr"         "knitr"       
+##  [5] "shiny"        "xts"          "lattice"      "digest"      
+##  [9] "gtable"       "reshape2"     "scales"       "proto"       
+## [13] "MASS"         "Rcpp"         "stringr"      "RColorBrewer"
+## [17] "dichromat"    "munsell"      "labeling"     "colorspace"  
+## [21] "evaluate"     "formatR"      "highr"        "markdown"    
+## [25] "mime"         "httpuv"       "caTools"      "RJSONIO"     
+## [29] "xtable"       "htmltools"    "bitops"       "zoo"         
+## [33] "SparseM"      "survival"     "Formula"      "latticeExtra"
+## [37] "cluster"      "maps"         "sp"           "foreign"     
+## [41] "mvtnorm"      "TH.data"      "sandwich"     "nlme"        
+## [45] "Matrix"       "bit"          "codetools"    "iterators"   
+## [49] "timeDate"     "quadprog"     "Hmisc"        "BH"          
+## [53] "quantreg"     "mapproj"      "hexbin"       "maptools"    
+## [57] "multcomp"     "testthat"     "mgcv"         "chron"       
+## [61] "reshape"      "fastmatch"    "bit64"        "abind"       
+## [65] "foreach"      "doMC"         "itertools"    "testit"      
+## [69] "rgl"          "XML"          "RCurl"        "Cairo"       
+## [73] "timeSeries"   "tseries"      "its"          "fts"         
+## [77] "tis"          "KernSmooth"
+
dg <- makeDepGraph(tags, enhances = TRUE, availPkgs = cranJuly2014)
+set.seed(1)
+plot(dg, legendPosition = c(-1, -1), vertex.size = 10, cex = 0.7)
+

+
+ + + + + + + + diff --git a/vignettes/miniCRAN-introduction.R b/vignettes/miniCRAN-introduction.R new file mode 100644 index 0000000..1a7a05d --- /dev/null +++ b/vignettes/miniCRAN-introduction.R @@ -0,0 +1,80 @@ +## ----make-repo-1--------------------------------------------------------- +library("miniCRAN") + +# use Revolution Analytics CRAN mirror +revolution <- c(CRAN = "http://cran.microsoft.com") + +# Specify list of packages to download +pkgs <- c("foreach") +pkgList <- pkgDep(pkgs, repos = revolution, type = "source", suggests = FALSE, + availPkgs = cranJuly2014) +pkgList + +## ----make-repo-2, eval=FALSE--------------------------------------------- +# # Create temporary folder for miniCRAN +# dir.create(pth <- file.path(tempdir(), "miniCRAN")) +# +# # Make repo for source and win.binary +# makeRepo(pkgList, path=pth, repos=revolution, type=c("source", "win.binary")) + +## ----make-repo-3, eval=FALSE--------------------------------------------- +# # List all files in miniCRAN +# list.files(pth, recursive = TRUE, full.names = FALSE) + +## ----make-repo-4, eval=FALSE--------------------------------------------- +# # Check for available packages +# pkgAvail(repos = pth, type = "win.binary")[, c(1:3, 5)] + +## ----make-repo-5, eval=FALSE--------------------------------------------- +# install.packages(pkgs, +# repos = paste0("file:///", pth), +# type = "source") + +## ----addto-repo-new-1, eval=FALSE---------------------------------------- +# # Add new packages (from CRAN) to the miniCRAN repo +# addPackage("Matrix", path = pth, repos = revolution, type = c("source", "win.binary")) +# pkgAvail(repos = pth, type = "win.binary")[, c(1:3, 5)] + +## ----addto-repo-old-1, eval=FALSE---------------------------------------- +# # create a data frame with the package and version info +# oldVers <- data.frame( +# package = c("foreach", "codetools", "iterators"), +# version = c("1.4.0", "0.2-7", "1.0.5"), +# stringsAsFactors = FALSE +# ) +# +# # download old source package version and create repo index +# addOldPackage(pkgList, path = pth, vers = oldVers$version, repos = revolution, type = "source") + +## ----addto-repo-old-2, eval=FALSE---------------------------------------- +# # List package versions in the miniCRAN repo (produces warning about duplicates) +# pkgVersionsSrc <- checkVersions(pkgList, path = pth, type = "source") +# pkgVersionsBin <- checkVersions(pkgList, path = pth, type = "win.binary") +# +# # After inspecting package versions, remove old versions +# basename(pkgVersionsSrc) # duplicate versions +# basename(pkgVersionsBin) +# +# file.remove(pkgVersionsSrc[c(2,4,6)]) +# +# # rebuild the package index after removing duplicate package versions +# updateRepoIndex(pth, type = c("source", "win.binary")) + +## ----addto-repo-old-3, eval=FALSE---------------------------------------- +# pkgAvail(pth, type = "source")[, c(1:3, 5)] # contains the old versions +# pkgAvail(pth, type = "win.binary")[, c(1:3, 5)] # contains the current versions + +## ----update-repo-1, eval=FALSE------------------------------------------- +# # Check if updated packages are available +# oldPackages(path = pth, repos = revolution, type = "source")[, 1:3] # should need update +# oldPackages(path = pth, repos = revolution, type = "win.binary")[, 1:3] # should be current + +## ----update-repo-2, eval=FALSE------------------------------------------- +# # Update available packages +# updatePackages(path = pth, repos = revolution, type = "source", ask = FALSE) # should need update +# updatePackages(path = pth, repos = revolution, type = "win.binary", ask = FALSE) # should be current + +## ----cleanup, include=FALSE, eval=FALSE---------------------------------- +# # Delete temporary folder +# unlink(pth, recursive = TRUE) + diff --git a/vignettes/miniCRAN-introduction.html b/vignettes/miniCRAN-introduction.html new file mode 100644 index 0000000..9f1f9cf --- /dev/null +++ b/vignettes/miniCRAN-introduction.html @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + +Using miniCRAN to create a local CRAN repository + + + + + + + + + + + + + + + + + +

Using miniCRAN to create a local CRAN repository

+

Andrie de Vries and Alex Chubaty

+

December 26, 2017

+ + + +

Start by creating the recursive dependency tree for your target packages.

+

For example, imagine a scenario where you want to create a repository that consists of the package foreach and its dependencies.

+

Start by creating the dependency list:

+
library("miniCRAN")
+
+# use Revolution Analytics CRAN mirror
+revolution <- c(CRAN = "http://cran.microsoft.com")
+
+# Specify list of packages to download
+pkgs <- c("foreach")
+pkgList <- pkgDep(pkgs, repos = revolution, type = "source", suggests = FALSE, 
+                  availPkgs = cranJuly2014)
+pkgList
+
## [1] "foreach"   "codetools" "iterators"
+

Next, create a repository with the function makeRepo(). In this example, get the required files for source packages as well as windows binaries:

+
# Create temporary folder for miniCRAN
+dir.create(pth <- file.path(tempdir(), "miniCRAN"))
+
+# Make repo for source and win.binary
+makeRepo(pkgList, path=pth, repos=revolution, type=c("source", "win.binary"))
+

Investigate the repository file structure:

+
# List all files in miniCRAN
+list.files(pth, recursive = TRUE, full.names = FALSE)
+

Use pkgAvail to list available packages in your repository:

+
# Check for available packages
+pkgAvail(repos = pth, type = "win.binary")[, c(1:3, 5)]
+
+

Install packages from your local repository

+

To install packages from a local repository, you need to use the URI convention file:/// to point to your file lcoation.

+
install.packages(pkgs, 
+                 repos = paste0("file:///", pth),
+                 type = "source")
+
+
+

Adding packages to an existing miniCRAN repository

+
+

Adding new packages from CRAN

+

After creating a local miniCRAN repository, additional packages and their dependencies can easily be added. This mechanism can also be used to re-add an existing package to the miniCRAN repo.

+
# Add new packages (from CRAN) to the miniCRAN repo
+addPackage("Matrix", path = pth, repos = revolution, type = c("source", "win.binary"))
+pkgAvail(repos = pth, type = "win.binary")[, c(1:3, 5)]
+

The value that is returned (invisibly) via addPackage is the number of packages written to the index file, i.e., the total number of packages in the repo of that type.

+
+
+

Adding an older version of a package from CRAN

+

To add a specific version of a package from CRAN (or another CRAN-like repository), we can easily download the source packages from the CRAN archives. Dependencies for old package versions cannot be determined automatically and must be specified by the user.

+

Note: in order to to add binaries of older packages, you will need to download the source and build the binaries on the intended platform yourself. You will need the appropriate R development tools installed in order to build package binaries from source.

+
# create a data frame with the package and version info
+oldVers <- data.frame(
+  package = c("foreach", "codetools", "iterators"),
+  version = c("1.4.0", "0.2-7", "1.0.5"),
+  stringsAsFactors = FALSE
+)
+
+# download old source package version and create repo index
+addOldPackage(pkgList, path = pth, vers = oldVers$version, repos = revolution, type = "source")
+

You will get a warning whenever there are multiple versions of a package saved in the repository. Currently, you need to manually remove duplicate versions before rebuilding the repository’s package index.

+

Note: This last step is important, otherwise you may end up with a repo in an inconsistent state.

+
# List package versions in the miniCRAN repo (produces warning about duplicates)
+pkgVersionsSrc <- checkVersions(pkgList, path = pth, type = "source")
+pkgVersionsBin <- checkVersions(pkgList, path = pth, type = "win.binary")
+
+# After inspecting package versions, remove old versions
+basename(pkgVersionsSrc) # duplicate versions
+basename(pkgVersionsBin)
+
+file.remove(pkgVersionsSrc[c(2,4,6)])
+
+# rebuild the package index after removing duplicate package versions
+updateRepoIndex(pth, type = c("source", "win.binary"))
+

To see the updated list of packages available in the miniCRAN repo:

+
pkgAvail(pth, type = "source")[, c(1:3, 5)] # contains the old versions
+pkgAvail(pth, type = "win.binary")[, c(1:3, 5)] # contains the current versions
+
+
+

Adding packages from other sources

+

This feature will be implemented in a future release.

+
+
+
+

Updating the packages in a miniCRAN repository

+

Checking for updated versions of the packages currently stored in the miniCRAN repository:

+
# Check if updated packages are available
+oldPackages(path = pth, repos = revolution, type = "source")[, 1:3] # should need update
+oldPackages(path = pth, repos = revolution, type = "win.binary")[, 1:3] # should be current
+

Update the versions of the packages currently stored in the miniCRAN repository. By default, a prompt is given to confirm the update for each package. This prompt can be suppressed using ask = FALSE, which will update all packages. Be careful using this option if you want to keep certain packages at an older version.

+
# Update available packages
+updatePackages(path = pth, repos = revolution, type = "source", ask = FALSE) # should need update
+updatePackages(path = pth, repos = revolution, type = "win.binary", ask = FALSE) # should be current
+
+ + + + + + + + diff --git a/vignettes/miniCRAN-non-CRAN-repos.R b/vignettes/miniCRAN-non-CRAN-repos.R new file mode 100644 index 0000000..c02e2a0 --- /dev/null +++ b/vignettes/miniCRAN-non-CRAN-repos.R @@ -0,0 +1,39 @@ +## ----setup--------------------------------------------------------------- +# Wrapper around available.packages --------------------------------------- + +index <- function(url, type = "source", filters = NULL, head = 5, cols = c("Package", "Version")){ + contribUrl <- contrib.url(url, type = type) + p <- available.packages(contribUrl, type = type, filters = filters) + p[1:head, cols] +} + + +## ----CRAN, eval=FALSE---------------------------------------------------- +# CRAN <- "http://cran.r-project.org" +# index(CRAN) + +## ----revo, eval=FALSE---------------------------------------------------- +# revoStable <- "http://packages.revolutionanalytics.com/cran/3.1/stable" +# index(revoStable) +# +# revoMirror <- "http://cran.revolutionanalytics.com" +# index(revoMirror) + +## ----rforge, eval=FALSE-------------------------------------------------- +# rforge <- "http://r-forge.r-project.org" +# index(rforge) + +## ----bioc, eval=FALSE---------------------------------------------------- +# bioc <- local({ +# env <- new.env() +# on.exit(rm(env)) +# evalq(source("http://bioconductor.org/biocLite.R", local = TRUE), env) +# biocinstallRepos() +# }) +# +# bioc +# bioc[grep("BioC", names(bioc))] +# +# +# index(bioc["BioCsoft"]) + diff --git a/vignettes/miniCRAN-non-CRAN-repos.html b/vignettes/miniCRAN-non-CRAN-repos.html new file mode 100644 index 0000000..5d595d6 --- /dev/null +++ b/vignettes/miniCRAN-non-CRAN-repos.html @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + +Using repositories other than CRAN with miniCRAN + + + + + + + + + + + + + + + + + +

Using repositories other than CRAN with miniCRAN

+

Andrie de Vries

+

December 26, 2017

+ + + +

Although the package name miniCRAN seems to indicate you can only use CRAN as a repository, you can in fact use any CRAN-like repository.

+

This vignette contains some examples of how to refer to different package repositories, including CRAN, alternative mirrors of CRAN, R-Forge as well as BioConductor.

+

To simplify the code to show the salient features, we use a little helper function, index() that is a simple wrapper around available.packages():

+
# Wrapper around available.packages ---------------------------------------
+ 
+index <- function(url, type = "source", filters = NULL, head = 5, cols = c("Package", "Version")){
+  contribUrl <- contrib.url(url, type = type)
+  p <- available.packages(contribUrl, type = type, filters = filters)
+  p[1:head, cols]
+}
+
+

Using CRAN

+

The URL for the master mirror in Austria:

+
CRAN <- "http://cran.r-project.org"
+index(CRAN)
+
+
+

Using a different mirror

+

You can also point to any other mirror, for example the stable version hosted by Revolution Analytics:

+
revoStable <- "http://packages.revolutionanalytics.com/cran/3.1/stable"
+index(revoStable)
+ 
+revoMirror <- "http://cran.revolutionanalytics.com"
+index(revoMirror)
+
+
+

Using R-forge

+

R-forge has CRAN-like structure:

+
rforge <- "http://r-forge.r-project.org"
+index(rforge)
+
+
+

Using BioConductor

+

Although BioConductor has a different preferred install mechanism, the underlying repository structure is also CRAN-like:

+
bioc <- local({
+  env <- new.env()
+  on.exit(rm(env))
+  evalq(source("http://bioconductor.org/biocLite.R", local = TRUE), env)
+  biocinstallRepos()
+})
+ 
+bioc
+bioc[grep("BioC", names(bioc))]
+ 
+ 
+index(bioc["BioCsoft"])
+
+ + + + + + + +