Using miniCRAN to identify package dependencies
-Andrie de Vries
+Andrie de +Vries
-March 20, 2024
+March 23, 2024
Source:vignettes/miniCRAN-dependency-graph.rmd
miniCRAN-dependency-graph.rmd
March 20, 2024
-The miniCRAN
package exposes two functions that provide information about dependencies:
The miniCRAN
package exposes two functions that provide
+information about dependencies:
-
-
The function
pkgDep()
returns a character vector with the names of dependencies. Internally,pkgDep()
is a wrapper aroundtools::package_dependencies()
, a base R function that, well, tells you about package dependencies. MypkgDep()
function is in one way a convenience, but more importantly it sets different defaults (more about this later).
-The function
makeDepGraph()
creates a graph representation of the dependencies.
+The function
pkgDep()
returns a character vector +with the names of dependencies. Internally,pkgDep()
is a +wrapper aroundtools::package_dependencies()
, a base R +function that, well, tells you about package dependencies. My +pkgDep()
function is in one way a convenience, but more +importantly it sets different defaults (more about this later).
+The function
makeDepGraph()
creates a graph +representation of the dependencies.
The package chron
neatly illustrates the different roles of Imports, Suggests and Enhances:
The package chron
neatly illustrates the different roles
+of Imports, Suggests and Enhances:
-
-
chron
Imports the base packages graphics and stats. This means thatchron
internally makes use of graphics and stats and will always load these packages.
-chron
Suggests the packages scales and ggplot2. This means thatchron
uses some functions from these packages in examples or in its vignettes. However, these functions are not necessary to usechron
-chron
Enhances the packagezoo
, meaning that it adds something tozoo
packages. These enhancements are made available to you if you havezoo
installed.
+chron
Imports the base packages +graphics and stats. This means thatchron
internally makes +use of graphics and stats and will always load these packages.
+chron
Suggests the packages scales +and ggplot2. This means thatchron
uses some functions from +these packages in examples or in its vignettes. However, these functions +are not necessary to usechron
+chron
Enhances the package +zoo
, meaning that it adds something tozoo
+packages. These enhancements are made available to you if you have +zoo
installed.
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.
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:
-
-
- First retrieve a list of
Suggests
andEnhances
, using a non-recursive dependency search
- - Next, perform a recursive search for all
Imports
,Depends
andLinkingTo
+ - First retrieve a list of
Suggests
and +Enhances
, using a non-recursive dependency search
+ - Next, perform a recursive search for all
Imports
, +Depends
andLinkingTo
The resulting list of packages should then contain the complete list necessary to satisfy all dependencies. In code:
+The resulting list of packages should then contain the complete list +necessary to satisfy all dependencies. In code:
@@ -118,18 +142,23 @@-A worked example using the pac ## [6] "labeling" "colorspace" "Rcpp" "digest" "gtable" ## [11] "reshape2" "scales" "proto" "MASS" "stringr" ## [16] "ggplot2"
To create an igraph plot of the dependencies, use the function makeDepGraph()
and plot the results:
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.
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:
+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)
Using miniCRAN to create and maintain a local CRAN repository
-Andrie de Vries and Alex Chubaty
+Andrie de Vries +and Alex Chubaty
-March 20, 2024
+March 23, 2024
Source:vignettes/miniCRAN-introduction.rmd
miniCRAN-introduction.rmd
March 20, 2024
-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 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")
@@ -102,7 +107,9 @@ March 20, 2024
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:
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"))
@@ -113,14 +120,17 @@ March 20, 2024
# List all files in miniCRAN
list.files(pth, recursive = TRUE, full.names = FALSE)
-Use pkgAvail
to list available packages in your repository:
+Use pkgAvail
to list available packages in your
+repository:
Install packages from your local repository
-To install packages from a local repository, you need to use the Uniform Resource Identifier (URI) convention file:///
to point to your file location.
+To install packages from a local repository, you need to use the Uniform
+Resource Identifier (URI) convention file:///
to point
+to your file location.
install.packages(pkgs,
repos = paste0("file:///", pth),
@@ -132,18 +142,28 @@ Adding packages to a
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.
+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.
+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.
+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(
@@ -154,8 +174,11 @@ Adding an older version
# 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.
+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")
@@ -169,7 +192,8 @@ Adding an older version
# 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:
+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
@@ -183,12 +207,17 @@ Adding packages from other sources
Updating the packages in a miniCRAN repository
-Checking for updated versions of the packages currently stored in the 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 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
diff --git a/articles/miniCRAN-non-CRAN-repos.html b/articles/miniCRAN-non-CRAN-repos.html
index d16442e..5ec00d0 100644
--- a/articles/miniCRAN-non-CRAN-repos.html
+++ b/articles/miniCRAN-non-CRAN-repos.html
@@ -74,12 +74,14 @@
-
+
+
Using repositories other than CRAN with miniCRAN
- Andrie de Vries
+ Andrie de
+Vries
- March 20, 2024
+ March 23, 2024
Source: vignettes/miniCRAN-non-CRAN-repos.rmd
miniCRAN-non-CRAN-repos.rmd
@@ -87,9 +89,15 @@ March 20, 2024
-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()
:
+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 ---------------------------------------
@@ -109,7 +117,8 @@ Using CRAN
Using a different mirror
-You can also point to any other mirror, for example the stable version hosted by Revolution Analytics:
+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)
@@ -128,7 +137,8 @@ Using R-forge
Using BioConductor
-Although BioConductor has a different preferred install mechanism, the underlying repository structure is also CRAN-like:
+Although BioConductor has a different preferred install mechanism,
+the underlying repository structure is also CRAN-like:
bioc <- local({
env <- new.env()
diff --git a/index.html b/index.html
index 621292b..0982bc5 100644
--- a/index.html
+++ b/index.html
@@ -90,6 +90,7 @@
+
Create a mini version of CRAN containing only selected packages
Introduction
diff --git a/pkgdown.yml b/pkgdown.yml
index f2914c1..06802f4 100644
--- a/pkgdown.yml
+++ b/pkgdown.yml
@@ -1,11 +1,11 @@
-pandoc: 2.9.2.1
+pandoc: 3.1.11
pkgdown: 2.0.7
pkgdown_sha: ~
articles:
miniCRAN-dependency-graph: miniCRAN-dependency-graph.html
miniCRAN-introduction: miniCRAN-introduction.html
miniCRAN-non-CRAN-repos: miniCRAN-non-CRAN-repos.html
-last_built: 2024-03-20T17:58Z
+last_built: 2024-03-23T14:22Z
urls:
reference: http://andrie.github.io/miniCRAN/reference
article: http://andrie.github.io/miniCRAN/articles
diff --git a/reference/index.html b/reference/index.html
index cf3c39b..ad32f21 100644
--- a/reference/index.html
+++ b/reference/index.html
@@ -213,7 +213,7 @@ Other
List pre-built packages in a directory based on file extension
-
-
miniCRAN-package
_PACKAGE
miniCRAN
minicran
+ miniCRAN-package
miniCRAN
minicran
- description
-