Metadata and package cache for CRAN-like repositories. This is a utility package to be used by package management tools that want to take advantage of caching.
Details
Metadata and package cache for CRAN-like repositories. This is a utility package to be used by package management tools that want to take advantage of caching.
Installation
You can install the released version of pkgcache from CRAN with:
install.packages("pkgcache")
If you need the development version, you can install it from GitHub with:
pak::pak("r-lib/pkgcache")
Metadata cache
meta_cache_list()
lists all packages in the metadata cache. It
includes Bioconductor package, and all versions (i.e. both binary and
source) of the packages for the current platform and R version.
(We load the pillar package, because it makes the pkgcache data frames print nicer, similarly to tibbles.)
library(pkgcache)
library(pillar)
meta_cache_list()
#> # A data frame: 48,094 x 32
#> package version depends suggests license imports linkingto archs enhances
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 A3 1.0.0 R (>= ~ randomF~ GPL (>~ <NA> <NA> <NA> <NA>
#> 2 AATtools 0.0.2 R (>= ~ <NA> GPL-3 magrit~ <NA> <NA> <NA>
#> 3 ABACUS 1.0.0 R (>= ~ rmarkdo~ GPL-3 ggplot~ <NA> <NA> <NA>
#> 4 ABC.RAP 0.9.0 R (>= ~ knitr, ~ GPL-3 graphi~ <NA> <NA> <NA>
#> 5 ABCanalysis 1.2.1 R (>= ~ <NA> GPL-3 plotrix <NA> <NA> <NA>
#> 6 ABCoptim 0.15.0 <NA> testtha~ MIT + ~ Rcpp, ~ Rcpp ABCo~ <NA>
#> 7 ABCp2 1.2 MASS <NA> GPL-2 <NA> <NA> <NA> <NA>
#> 8 ABHgenotyp~ 1.0.1 <NA> knitr, ~ GPL-3 ggplot~ <NA> <NA> <NA>
#> 9 ABM 0.4.1 <NA> <NA> GPL (>~ R6, Rc~ Rcpp ABM.~ <NA>
#> 10 ABPS 0.3 <NA> testthat GPL (>~ kernlab <NA> <NA> <NA>
#> # i 48,084 more rows
#> # i 23 more variables: license_restricts_use <chr>, priority <chr>,
#> # license_is_foss <chr>, os_type <chr>, repodir <chr>, rversion <chr>,
#> # platform <chr>, needscompilation <chr>, ref <chr>, type <chr>,
#> # direct <lgl>, status <chr>, target <chr>, mirror <chr>, sources <list>,
#> # filesize <int>, sha256 <chr>, sysreqs <chr>, built <chr>, published <dttm>,
#> # deps <list>, md5sum <chr>, path <chr>
meta_cache_deps()
and meta_cache_revdeps()
can be used to look up
dependencies and reverse dependencies.
The metadata is updated automatically if it is older than seven days,
and it can also be updated manually with meta_cache_update()
.
See the cranlike_metadata_cache
R6 class for a lower level API, and
more control.
Package cache
Package management tools may use the pkg_cache_*
functions and in
particular the package_cache
class, to make use of local caching of
package files.
The pkg_cache_*
API is high level, and uses a user level cache:
pkg_cache_summary()
#> $cachepath
#> [1] "/Users/gaborcsardi/Library/Caches/org.R-project.R/R/pkgcache/pkg"
#>
#> $files
#> [1] 40
#>
#> $size
#> [1] 61300737
pkg_cache_list()
#> # A data frame: 40 x 11
#> fullpath path package url etag sha256 version platform built vignettes
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <int> <int>
#> 1 /Users/gab~ arch~ <NA> http~ "\"1~ 9da51~ <NA> <NA> NA NA
#> 2 /Users/gab~ bin/~ cli http~ "\"1~ b24b4~ 3.6.2 x86_64-~ NA NA
#> 3 /Users/gab~ bin/~ jose http~ "\"7~ b1bac~ 1.2.0 aarch64~ NA NA
#> 4 /Users/gab~ src/~ gh <NA> <NA> <NA> 1.4.0.~ source 1 0
#> 5 /Users/gab~ src/~ gh <NA> <NA> <NA> 1.4.0.~ aarch64~ 1 0
#> 6 /Users/gab~ bin/~ gh http~ "\"1~ f5daf~ 1.4.0 aarch64~ NA NA
#> 7 /Users/gab~ src/~ tic <NA> <NA> 11103~ <NA> <NA> 0 NA
#> 8 /Users/gab~ src/~ tic <NA> <NA> 11103~ 0.14.0 source 1 0
#> 9 /Users/gab~ src/~ tic <NA> <NA> 11103~ 0.14.0 aarch64~ 1 0
#> 10 /Users/gab~ bin/~ rhub http~ "\"f~ af2d6~ 1.1.2 aarch64~ NA NA
#> # i 30 more rows
#> # i 1 more variable: rversion <chr>
pkg_cache_find(package = "dplyr")
#> # A data frame: 0 x 11
#> # i 11 variables: fullpath <chr>, path <chr>, package <chr>, url <chr>,
#> # etag <chr>, sha256 <chr>, version <chr>, platform <chr>, built <int>,
#> # vignettes <int>, rversion <chr>
pkg_cache_add_file()
can be used to add a file,
pkg_cache_delete_files()
to remove files, pkg_cache_get_files()
to
copy files out of the cache.
The package_cache
class provides a finer API.
Installed packages
pkgcache contains a very fast DCF parser to parse PACKAGES*
files, or
the DESCRIPTION
files in installed packages. parse_packages()
parses
all fields from PACKAGES
, PACKAGES.gz
or PACKAGES.rds
files.
parse_installed()
reads all metadata from packages installed into a
library:
parse_installed()
#> # A data frame: 888 x 128
#> Package Type Title Version Date `Authors@R` Maintainer Description Imports
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 AdaptGa~ Pack~ Gaus~ 1.6 2024~ "c(person(~ Michael T~ "Multimoda~ "Rcpp,~
#> 2 Annotat~ <NA> Mani~ 1.64.1 <NA> <NA> Bioconduc~ "Implement~ "DBI, ~
#> 3 Annotat~ <NA> Tool~ 1.42.2 <NA> <NA> Bioconduc~ "Provides ~ "DBI, ~
#> 4 AsioHea~ Pack~ 'Asi~ 1.22.1~ 2022~ <NA> Dirk Edde~ "'Asio' is~ <NA>
#> 5 AutoQua~ <NA> Auto~ 1.0.1 2023~ "\n c(p~ Adrian An~ "R package~ "bit64~
#> 6 BH Pack~ Boos~ 1.81.0~ 2023~ <NA> Dirk Edde~ "Boost pro~ <NA>
#> 7 BayesFa~ Pack~ Comp~ 0.9.12~ 2022~ "c(person(~ Richard D~ "A suite o~ "pbapp~
#> 8 Biobase <NA> Biob~ 2.62.0 <NA> "c(\n p~ Bioconduc~ "Functions~ "metho~
#> 9 BiocBas~ <NA> Gene~ 1.4.0 <NA> "c(\n per~ Marcel Ra~ "The packa~ "metho~
#> 10 BiocFil~ <NA> Mana~ 2.10.1 <NA> "c(person(~ Lori Shep~ "This pack~ "metho~
#> # i 878 more rows
#> # i 119 more variables: Suggests <chr>, LinkingTo <chr>, Depends <chr>,
#> # License <chr>, LazyLoad <chr>, URL <chr>, Encoding <chr>,
#> # NeedsCompilation <chr>, VignetteBuilder <chr>, BugReports <chr>,
#> # Packaged <chr>, Author <chr>, Repository <chr>, `Date/Publication` <chr>,
#> # Built <chr>, Archs <chr>, RemoteType <chr>, RemotePkgRef <chr>,
#> # RemoteRef <chr>, RemoteRepos <chr>, RemotePkgPlatform <chr>, ...
Bioconductor support
Both the metadata cache and the package cache support Bioconductor by
default, automatically. See the BioC_mirror
option and the
R_BIOC_MIRROR
and R_BIOC_VERSION
environment variables below to
configure Bioconductor support.
Package Options
The
BioC_mirror
option can be used to select a Bioconductor mirror. This takes priority over theR_BIOC_MIRROR
environment variable.You can use the
pkg.current_platform
option to set the platform string for the current platform for thecurrent_r_platform()
function. This is useful if pkgcache didn’t detect the platform correctly. Alternatively, you can use thePKG_CURRENT_PLATFORM
environment variable. The option takes priority.pkgcache_timeout
is the HTTP timeout for all downloads. It is in seconds, and the limit for downloading the whole file. Defaults to 3600, one hour. It corresponds to theTIMEOUT
libcurl option.pkgcache_connecttimeout
is the HTTP timeout for the connection phase. It is in seconds and defaults to 30 seconds. It corresponds to theCONNECTTIMEOUT
libcurl option.pkgcache_low_speed_limit
andpkgcache_low_speed_time
are used for a more sensible HTTP timeout. If the download speed is less thanpkgcache_low_speed_limit
bytes per second for at leastpkgcache_low_speed_time
seconds, the download errors. They correspond to theLOW_SPEED_LIMIT
andLOW_SPEED_TIME
curl options.
Package environment variables
The
R_BIOC_VERSION
environment variable can be used to override the default Bioconductor version detection and force a given version. E.g. this can be used to force the development version of Bioconductor.The
R_BIOC_MIRROR
environment variable can be used to select a Bioconductor mirror. TheBioC_mirror
option takes priority over this, if set.You can use the
PKG_CURRENT_PLATFORM
environment variable to set the platform string for the current platform for thecurrent_r_platform()
function. This is useful if pkgcache didn’t detect the platform correctly. Alternatively, you can use thepkg.current_platofrm
option, which takes. priority over the environment variable.PKGCACHE_PPM_REPO
is the name of the Posit Package Manager repository to use. Defaults to"cran"
.PKGCACHE_PPM_URL
is the base URL of the Posit Package Manager instance to use. It defaults to the URL of the Posit Public Package Manager instance at https://packagemanager.posit.co/client/#/.PKGCACHE_TIMEOUT
is the HTTP timeout for all downloads. It is in seconds, and the limit for downloading the whole file. Defaults to 3600, one hour. It corresponds to theTIMEOUT
libcurl option. Thepkgcache_timeout
option has priority over this, if set.PKGCACHE_CONNECTTIMEOUT
is the HTTP timeout for the connection phase. It is in seconds and defaults to 30 seconds. It corresponds to theCONNECTTIMEOUT
libcurl option. Thepkgcache_connecttimeout
option takes precedence over this, if set.PKGCACHE_LOW_SPEED_LIMIT
andPKGCACHE_LOW_SPEED_TIME
are used for a more sensible HTTP timeout. If the download speed is less thanPKGCACHE_LOW_SPEED_LIMIT
bytes per second for at leastPKGCACHE_LOW_SPEED_TIME
seconds, the download errors. They correspond to theLOW_SPEED_LIMIT
andLOW_SPEED_TIME
curl options. Thepkgcache_low_speed_time
andpkgcache_low_speed_limit
options have priority over these environment variables, if they are set.R_PKG_CACHE_DIR
is used for the cache directory, if set. (Otherwisetools::R_user_dir("pkgcache", "cache")
is used, see alsometa_cache_summary()
andpkg_cache_summary()
).
Using pkgcache in CRAN packages
If you use pkgcache in your CRAN package, please make sure that
you don’t use pkgcache in your examples, and
you set the
R_USER_CACHE_DIR
environment variable to a temporary directory (e.g. viatempfile()
) during test cases. See thetests/testthat/setup.R
file in pkgcache for an example.
This is to make sure that pkgcache does not modify the user’s files
while running R CMD check
.
Code of Conduct
Please note that the pkgcache project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
License
MIT (c) Posit Software, PBC
Author
Maintainer: Gábor Csárdi csardi.gabor@gmail.com
Other contributors:
Posit Software, PBC [copyright holder, funder]