The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Title: Cache 'CRAN'-Like Metadata and R Packages
Version: 2.2.4
Description: 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.
License: MIT + file LICENSE
URL: https://r-lib.github.io/pkgcache/, https://github.com/r-lib/pkgcache
BugReports: https://github.com/r-lib/pkgcache/issues
Depends: R (≥ 3.4)
Imports: callr (≥ 2.0.4.9000), cli (≥ 3.2.0), curl (≥ 3.2), filelock, jsonlite, processx (≥ 3.3.0.9001), R6, tools, utils
Suggests: covr, debugme, desc, fs, keyring, pillar, pingr, rprojroot, sessioninfo, spelling, testthat (≥ 3.2.0), webfakes (≥ 1.1.5), withr, zip
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Config/usethis/last-upkeep: 2025-04-30
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.3.2.9000
NeedsCompilation: yes
Packaged: 2025-05-26 11:13:00 UTC; gaborcsardi
Author: Gábor Csárdi [aut, cre], Posit Software, PBC ROR ID [cph, fnd]
Maintainer: Gábor Csárdi <csardi.gabor@gmail.com>
Repository: CRAN
Date/Publication: 2025-05-26 14:10:02 UTC

Cache for package data and metadata

Description

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: 50,641 x 33
#>    package    version depends suggests license md5sum sha256sum needscompilation
#>    <chr>      <chr>   <chr>   <chr>    <chr>   <chr>  <chr>     <chr>           
#>  1 A3         1.0.0   R (>= ~ randomF~ GPL (>~ 929a4~ "\n     ~ no              
#>  2 AATtools   0.0.3   R (>= ~ <NA>     GPL-3   de2ec~ "\n     ~ no              
#>  3 ABACUS     1.0.0   R (>= ~ rmarkdo~ GPL-3   28795~ "\n     ~ no              
#>  4 ABC.RAP    0.9.0   R (>= ~ knitr, ~ GPL-3   0158e~ "\n     ~ no              
#>  5 ABCanalys~ 1.2.1   R (>= ~ <NA>     GPL-3   4cbe1~ "\n     ~ no              
#>  6 ABCoptim   0.15.0  <NA>    testtha~ MIT + ~ a294d~ "\n     ~ yes             
#>  7 ABCp2      1.2     MASS    <NA>     GPL-2   d049b~  <NA>     no              
#>  8 ABHgenoty~ 1.0.1   <NA>    knitr, ~ GPL-3   fce25~ "\n     ~ no              
#>  9 ABM        0.4.3   <NA>    <NA>     GPL (>~ 7aaae~ "\n     ~ yes             
#> 10 ABPS       0.3     <NA>    testthat GPL (>~ d3f00~ "\n     ~ no              
#> # i 50,631 more rows
#> # i 25 more variables: imports <chr>, linkingto <chr>, archs <chr>,
#> #   enhances <chr>, license_restricts_use <chr>, priority <chr>, os_type <chr>,
#> #   license_is_foss <chr>, repodir <chr>, rversion <chr>, platform <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>, 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] 475
#> 
#> $size
#> [1] 669462030
pkg_cache_list()
#> # A data frame: 475 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~ src/~ remotes <NA>  <NA>  5b7eb~ <NA>    <NA>         0        NA
#>  2 /Users/gab~ src/~ remotes <NA>  <NA>  5b7eb~ 2.5.0.~ source       1         0
#>  3 /Users/gab~ src/~ remotes <NA>  <NA>  5b7eb~ 2.5.0.~ aarch64~     1         0
#>  4 /Users/gab~ src/~ cli     <NA>  <NA>  9d6e9~ <NA>    <NA>         0        NA
#>  5 /Users/gab~ src/~ cli     <NA>  <NA>  9d6e9~ 3.6.3.~ source       1         0
#>  6 /Users/gab~ src/~ cli     <NA>  <NA>  9d6e9~ 3.6.3.~ aarch64~     1         0
#>  7 /Users/gab~ src/~ cli     <NA>  <NA>  8a0b8~ <NA>    <NA>         0        NA
#>  8 /Users/gab~ src/~ cli     <NA>  <NA>  8a0b8~ 3.6.3.~ source       1         0
#>  9 /Users/gab~ src/~ cli     <NA>  <NA>  8a0b8~ 3.6.3.~ aarch64~     1         0
#> 10 /Users/gab~ src/~ cli     <NA>  <NA>  2dd91~ <NA>    <NA>         0        NA
#> # i 465 more rows
#> # i 1 more variable: rversion <chr>
pkg_cache_find(package = "dplyr")
#> # A data frame: 2 x 11
#>   fullpath     path  package url   etag  sha256 version platform built vignettes
#>   <chr>        <chr> <chr>   <chr> <chr> <chr>  <chr>   <chr>    <int>     <int>
#> 1 /Users/gabo~ bin/~ dplyr   http~ "\"6~ 721c2~ 1.1.4   aarch64~    NA        NA
#> 2 /Users/gabo~ bin/~ dplyr   http~ "\"1~ 721c2~ 1.1.4   aarch64~    NA        NA
#> # i 1 more variable: 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: 606 x 125
#>    Package      Title   Version `Authors@R` Description URL   BugReports License
#>    <chr>        <chr>   <chr>   <chr>       <chr>       <chr> <chr>      <chr>  
#>  1 AzureAuth    Authen~ 1.3.3   "c(\n    p~ "Provides ~ "htt~ https://g~ MIT + ~
#>  2 AzureGraph   Simple~ 1.3.4   "c(\n    p~ "A simple ~ "htt~ https://g~ MIT + ~
#>  3 AzureRMR     Interf~ 2.4.4   "c(\n    p~ "A lightwe~ "htt~ https://g~ MIT + ~
#>  4 AzureStor    Storag~ 3.7.0   "c(\n    p~ "Manage st~ "htt~ https://g~ MIT + ~
#>  5 BH           Boost ~ 1.84.0~  <NA>       "Boost pro~ "htt~ https://g~ BSL-1.0
#>  6 Biobase      Biobas~ 2.64.0  "c(\n    p~ "Functions~ "htt~ https://g~ Artist~
#>  7 BiocGenerics S4 gen~ 0.52.0   <NA>       "The packa~ "htt~ https://g~ Artist~
#>  8 BiocManager  Access~ 1.30.23 "c(\n    p~ "A conveni~ "htt~ https://g~ Artist~
#>  9 BiocVersion  Set th~ 3.19.1  "c(\n    p~ "This pack~  <NA> <NA>       Artist~
#> 10 CompQuadForm Distri~ 1.4.3    <NA>       "Computes ~  <NA> <NA>       GPL (>~
#> # i 596 more rows
#> # i 117 more variables: VignetteBuilder <chr>, Depends <chr>, Imports <chr>,
#> #   Suggests <chr>, RoxygenNote <chr>, NeedsCompilation <chr>, Packaged <chr>,
#> #   Author <chr>, Maintainer <chr>, Repository <chr>, `Date/Publication` <chr>,
#> #   Built <chr>, RemoteType <chr>, RemotePkgRef <chr>, RemoteRef <chr>,
#> #   RemoteRepos <chr>, RemotePkgPlatform <chr>, RemoteSha <chr>, Type <chr>,
#> #   Date <chr>, biocViews <chr>, LazyLoad <chr>, Collate <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

Package environment variables

Using pkgcache in CRAN packages

If you use pkgcache in your CRAN package, please make sure that

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(s)

Maintainer: Gábor Csárdi csardi.gabor@gmail.com

Other contributors:

See Also

Useful links:


Query Bioconductor version information

Description

Various helper functions to deal with Bioconductor repositories. See https://www.bioconductor.org/ for more information on Bioconductor.

Usage

bioc_version(r_version = getRversion(), forget = FALSE)

bioc_version_map(forget = FALSE)

bioc_devel_version(forget = FALSE)

bioc_release_version(forget = FALSE)

bioc_repos(bioc_version = "auto", forget = FALSE)

Arguments

r_version

The R version number to match.

forget

Use TRUE to avoid caching the Bioconductor mapping.

bioc_version

Bioconductor version string or package_version object, or the string "auto" to use the one matching the current R version.

Details

bioc_version() queries the matching Bioconductor version for an R version, defaulting to the current R version

bioc_version_map() returns the current mapping between R versions and Bioconductor versions.

bioc_devel_version() returns the version number of the current Bioconductor devel version.

bioc_release_version() returns the version number of the current Bioconductor release.

bioc_repos() returns the Bioconductor repository URLs.

See the BioC_mirror option and the R_BIOC_MIRROR and R_BIOC_VERSION environment variables in the pkgcache manual page. They can be used to customize the desired Bioconductor version.

Value

bioc_version() returns a package_version object.

bioc_version_map() returns a data frame with columns:

bioc_devel_version() returns a package_version object.

bioc_release_version() returns a package_version object.

bioc_repos() returns a named character vector.

Examples


bioc_version()
bioc_version("4.0")
bioc_version("4.1")


bioc_version_map()


bioc_devel_version()


bioc_release_version()


bioc_repos()


Call func and then call callback with the result

Description

callback will be called with two arguments, the first one will the error object if func() threw an error, or NULL otherwise. The second argument is NULL on error, and the result of func() otherwise.

Usage

call_with_callback(func, callback, info = NULL)

Arguments

func

Function to call.

callback

Callback to call with the result of func(), or the error thrown.

info

Extra info to add to the error object. Must be a named list.


Load the cache, asynchronously, with as little work as possible

Description

  1. If it is already loaded, and fresh return it.

  2. Otherwise try the replica RDS.

  3. Otherwise try the primary RDS.

  4. Otherwise try the primary PACKAGES files.

  5. Otherwise update the replica PACKAGES files, the replica RDS, and then also the primary PACKAGES and RDS.

Usage

cmc__async_ensure_cache(self, private, max_age)

Arguments

self

self

private

private self

max_age

Maximum age allowed to consider the data current.

Value

Metadata.


Load metadata from the primary cache's PACKAGES files

Description

If they are not available, or outdated, it throws an error. Otherwise they are copied to the replica cache, and then used to create the RDS file. The RDS file is then written back to the primary cache and also loaded.

Usage

cmc__load_primary_pkgs(self, private, max_age)

Arguments

self

self

private

private self

max_age

Max age to consider the files current.

Value

Metadata.


Load the metadata from the primary cache's RDS file

Description

If it exists and current, then the replica RDS is updated to it as well, and the data is returned. Otherwise throws an error.

Usage

cmc__load_primary_rds(self, private, max_age)

Arguments

self

Self.

private

Private self.

max_age

Maximum age allowed for the RDS file to be considered as current.

Value

Metadata.


Try to load the package metadata asynchronously, from the replica RDS

Description

If the replica has the RDS data, it is loaded and returned. Otherwise throws an error.

Usage

cmc__load_replica_rds(self, private, max_age)

Arguments

self

Self.

private

Private self.

max_age

Maximum age allowed for the RDS file to be considered as current.

Value

The metadata.


Update the primary cache from the replica cache

Description

Update the primary cache from the replica cache

Usage

cmc__update_primary(self, private, rds, packages, lock)

Arguments

self

self

private

private self

rds

Whether to update the RDS file.

packages

Whether to update the PACKAGES files (+ ETag files).

Value

Nothing.


Update the PACKAGES files in the replica cache

Description

I.e. download them, if they have changed.

Usage

cmc__update_replica_pkgs(self, private)

Arguments

self

self

private

private self


Update the replica RDS from the PACKAGES files

Description

Also loads it afterwards.

Usage

cmc__update_replica_rds(self, private, alert)

Arguments

self

self

private

private self

alert

whether to show message about the update


Cache for CRAN archive data

Description

This is an R6 class that implements a cache from older CRAN package versions. For a higher level interface see the functions documented with cran_archive_list().

Details

The cache is similar to cranlike_metadata_cache and has the following layers:

It has a synchronous and an asynchronous API.

Usage

cac <- cran_archive_cache$new(
  primary_path = NULL,
  replica_path = tempfile(),
  cran_mirror = default_cran_mirror(),
  update_after = as.difftime(7, units = "days"),
)

cac$list(packages = NULL, update_after = NULL)
cac$async_list(packages = NULL, update_after = NULL)

cac$update()
cac$async_update()

cac$check_update()
cac$async_check_update()

cac$summary()

cac$cleanup(force = FALSE)

Arguments

Details

Create a new archive cache with cran_archive_cache$new(). Multiple caches are independent, so e.g. if you update one of them, the other existing caches are not affected.

cac$list() lists the versions of the specified packages, or all packages, if none were specified. cac$async_list() is the same, but asynchronous.

cac$update() updates the cache. It always downloads the new metadata. cac$async_update() is the same, but asynchronous.

cac$check_update() updates the cache if there is a newer version available. cac$async_check_update() is the same, but asynchronous.

cac$summary() returns a summary of the archive cache, a list with entries:

cac$cleanup() cleans up the cache files.

Columns

cac$list() returns a data frame with columns:

Examples


arch <- cran_archive_cache$new()
arch$update()
arch$list()


Data about older versions of CRAN packages

Description

CRAN mirrors store older versions of packages in ⁠/src/contrib/Archive⁠, and they also store some metadata about them in ⁠/src/contrib/Meta/archive.rds⁠. pkgcache can download and cache this metadata.

Usage

cran_archive_list(
  cran_mirror = default_cran_mirror(),
  update_after = as.difftime(7, units = "days"),
  packages = NULL
)

cran_archive_update(cran_mirror = default_cran_mirror())

cran_archive_cleanup(cran_mirror = default_cran_mirror(), force = FALSE)

cran_archive_summary(cran_mirror = default_cran_mirror())

Arguments

cran_mirror

CRAN mirror to use, see default_cran_mirror().

update_after

difftime object. Automatically update the cache if it gets older than this. Set it to Inf to avoid updates. Defaults to seven days.

packages

Character vector. Only report these packages.

force

Force cleanup in non-interactive mode.

Details

cran_archive_list() lists all versions of all (or some) packages. It updates the cached data first, if it is older than the specified limit.

cran_archive_update() updates the archive cache.

cran_archive_cleanup() cleans up the archive cache for cran_mirror.

cran_archive_summary() prints a summary about the archive cache.

Value

cran_archive_list() returns a data frame with columns:

cran_archive_update() returns all archive data in a data frame, in the same format as cran_archive_list(), invisibly.

cran_archive_cleanup() returns nothing.

cran_archive_summary() returns a named list with elements:

See Also

The cran_archive_cache class for more flexibility.

Examples


cran_archive_list(packages = "readr")


Metadata cache for a CRAN-like repository

Description

This is an R6 class that implements the metadata cache of a CRAN-like repository. For a higher level interface, see the meta_cache_list(), meta_cache_deps(), meta_cache_revdeps() and meta_cache_update() functions.

Details

The cache has several layers:

It has a synchronous and an asynchronous API.

Usage

cmc <- cranlike_metadata_cache$new(
  primary_path = NULL, replica_path = tempfile(),
  platforms = default_platforms(), r_version = getRversion(),
  bioc = TRUE, cran_mirror = default_cran_mirror(),
  repos = getOption("repos"),
  update_after = as.difftime(7, units = "days"))

cmc$list(packages = NULL)
cmc$async_list(packages = NULL)

cmc$deps(packages, dependencies = NA, recursive = TRUE)
cmc$async_deps(packages, dependencies = NA, recursive = TRUE)

cmc$revdeps(packages, dependencies = NA, recursive = TRUE)
cmc$async_revdeps(packages, dependencies = NA, recursive = TRUE)

cmc$update()
cmc$async_update()
cmc$check_update()
cmc$asnyc_check_update()

cmc$summary()

cmc$cleanup(force = FALSE)

Arguments

Details

cranlike_metadata_cache$new() creates a new cache object. Creation does not trigger the population of the cache. It is only populated on demand, when queries are executed against it. In your package, you may want to create a cache instance in the .onLoad() function of the package, and store it in the package namespace. As this is a cheap operation, the package will still load fast, and then the package code can refer to the common cache object.

cmc$list() lists all (or the specified) packages in the cache. It returns a data frame, see the list of columns below.

cmc$async_list() is similar, but it is asynchronous, it returns a deferred object.

cmc$deps() returns a data frame, with the (potentially recursive) dependencies of packages.

cmc$async_deps() is the same, but it is asynchronous, it returns a deferred object.

cmc$revdeps() returns a data frame, with the (potentially recursive) reverse dependencies of packages.

cmc$async_revdeps() does the same, asynchronously, it returns an deferred object.

cmc$update() updates the the metadata (as needed) in the cache, and then returns a data frame with all packages, invisibly.

cmc$async_update() is similar, but it is asynchronous.

cmc$check_update() checks if the metadata is current, and if it is not, it updates it.

cmc$async_check_update() is similar, but it is asynchronous.

cmc$summary() lists metadata about the cache, including its location and size.

cmc$cleanup() deletes the cache files from the disk, and also from memory.

Columns

The metadata data frame contains all available versions (i.e. sources and binaries) for all packages. It usually has the following columns, some might be missing on some platforms.

The data frame contains some extra columns as well, these are for internal use only.

Examples


dir.create(cache_path <- tempfile())
cmc <- cranlike_metadata_cache$new(cache_path, bioc = FALSE)
cmc$list()
cmc$list("pkgconfig")
cmc$deps("pkgconfig")
cmc$revdeps("pkgconfig", recursive = FALSE)


R platforms

Description

R platforms

Usage

current_r_platform()

current_r_platform_data()

default_platforms()

Details

current_r_platform() detects the platform of the current R version. current_r_platform_data() is similar, but returns the raw data instead of a character scalar.

By default pkgcache works with source packages and binary packages for the current platform. You can change this, by providing different platform names as arguments to cranlike_metadata_cache$new(), repo_status(), etc.

These functions accept the following platform names:

default_platfoms() returns the default platforms for the current R session. These typically consist of the detected platform of the current R session, and "source", for source packages.

Value

current_r_platform() returns a character scalar.

current_r_platform_data() returns a data frame with character scalar columns:

default_platforms() returns a character vector of the default platforms.

Examples

current_r_platform()
default_platforms()

Create an error object for a rejected deferred computation

Description

Usage

def__make_error_object(self, private, err)

Arguments

self

self

private

private self

Value

error object


Query the default CRAN repository for this session

Description

If options("repos") (see options()) contains an entry called "CRAN", then that is returned. If it is a list, it is converted to a character vector.

Usage

default_cran_mirror()

Details

Otherwise the RStudio CRAN mirror is used.

Value

A named character vector of length one, where the name is "CRAN".

Examples

default_cran_mirror()

The R6 object that implements the global metadata cache

Description

This is used by the meta_cache_deps(), meta_cache_list(), etc. functions.

Usage

get_cranlike_metadata_cache()

Examples


get_cranlike_metadata_cache()
get_cranlike_metadata_cache()$list("cli")


Query the version of the graphics API

Description

A package compiled with a certain version of the graphics API will not work with R installations that use a different version.

Usage

get_graphics_api_version()

Value

An integer scalar, the version of the graphics API of this R version.

Examples

get_graphics_api_version()

Query UUID identifying the version of the R API

Description

Packages need to be recompiled if this id changes.

Usage

get_internals_id()

Value

String, a UUID.

Examples

get_internals_id()

Query CRAN(like) package data

Description

It uses CRAN and BioConductor packages, for the current platform and R version, from the default repositories.

Usage

meta_cache_deps(packages, dependencies = NA, recursive = TRUE)

meta_cache_revdeps(packages, dependencies = NA, recursive = TRUE)

meta_cache_update()

meta_cache_list(packages = NULL)

meta_cache_cleanup(force = FALSE)

meta_cache_summary()

Arguments

packages

Packages to query.

dependencies

Dependency types to query. See the dependencies parameter of utils::install.packages().

recursive

Whether to query recursive dependencies.

force

Whether to force cleanup without asking the user.

Details

meta_cache_list() lists all packages.

meta_cache_update() updates all metadata. Note that metadata is automatically updated if it is older than seven days.

meta_cache_deps() queries packages dependencies.

meta_cache_revdeps() queries reverse package dependencies.

meta_cache_summary() lists data about the cache, including its location and size.

meta_cache_cleanup() deletes the cache files from the disk.

Value

A data frame of the dependencies. For meta_cache_deps() and meta_cache_revdeps() it includes the queried packages as well.

Examples


meta_cache_list("pkgdown")
meta_cache_deps("pkgdown", recursive = FALSE)
meta_cache_revdeps("pkgdown", recursive = FALSE)


A simple package cache

Description

This is an R6 class that implements a concurrency safe package cache.

Details

By default these fields are included for every package:

Additional fields can be added as needed.

For a simple API to a session-wide instance of this class, see pkg_cache_summary() and the other functions listed there.

Usage

pc <- package_cache$new(path = NULL)

pc$list()
pc$find(..., .list = NULL)
pc$copy_to(..., .list = NULL)
pc$add(file, path, sha256 = shasum256(file), ..., .list = NULL)
pc$add_url(url, path, ..., .list = NULL, on_progress = NULL,
  http_headers = NULL)
pc$async_add_url(url, path, ..., .list = NULL, on_progress = NULL,
  http_headers = NULL)
pc$copy_or_add(target, urls, path, sha256 = NULL, ..., .list = NULL,
               on_progress = NULL, http_headers = NULL)
pc$async_copy_or_add(target, urls, path, ..., sha256 = NULL, ...,
               .list = NULL, on_progress = NULL, http_headers = NULL)
pc$update_or_add(target, urls, path, ..., .list = NULL,
               on_progress = NULL, http_headers = NULL)
pc$async_update_or_add(target, urls, path, ..., .list = NULL,
               on_progress = NULL, http_headers = NULL)
pc$delete(..., .list = NULL)

Arguments

Details

package_cache$new() attaches to the cache at path. (By default a platform dependent user level cache directory.) If the cache does not exists, it creates it.

pc$list() lists all files in the cache, returns a data frame with all the default columns, and potentially extra columns as well.

pc$find() list all files that match the specified criteria (fullpath, path, package, etc.). Custom columns can be searched for as well.

pc$copy_to() will copy the first matching file from the cache to target. It returns the data frame of all matching records, invisibly. If no file matches, it returns an empty (zero-row) data frame.

pc$add() adds a file to the cache.

pc$add_url() downloads a file and adds it to the cache.

pc$async_add_url() is the same, but it is asynchronous.

pc$copy_or_add() works like pc$copy_to(), but if the file is not in the cache, it tries to download it from one of the specified URLs first.

pc$async_copy_or_add() is the same, but asynchronous.

pc$update_or_add() is like pc$copy_to_add(), but if the file is in the cache it tries to update it from the urls, using the stored ETag to avoid unnecessary downloads.

pc$async_update_or_add() is the same, but it is asynchronous.

pc$delete() deletes the file(s) from the cache.

Examples


## Although package_cache usually stores packages, it may store
## arbitrary files, that can be search by metadata
pc <- package_cache$new(path = tempfile())
pc$list()

cat("foo\n", file = f1 <- tempfile())
cat("bar\n", file = f2 <- tempfile())
pc$add(f1, "/f1")
pc$add(f2, "/f2")
pc$list()
pc$find(path = "/f1")
pc$copy_to(target = f3 <- tempfile(), path = "/f1")
readLines(f3)

List metadata of installed packages

Description

This function is similar to utils::installed.packages(). See the differences below.

Usage

parse_installed(
  library = .libPaths(),
  priority = NULL,
  lowercase = FALSE,
  reencode = TRUE,
  packages = NULL
)

Arguments

library

Character vector of library paths.

priority

If not NULL then it may be a "base" "recommended" NA or a vector of these to select base packages, recommended packages or other packages. (These are the official, CRAN supported package priorities, but you may introduce others in non-CRAN packages.)

lowercase

Whether to convert keys in DESCRIPTION to lowercase.

reencode

Whether to re-encode strings in UTF-8, from the encodings specified in the DESCRIPTION files. Re-encoding is somewhat costly, and sometimes it is not important (e.g. when you only want to extract the dependencies of the installed packages).

packages

If not NULL, then it must be a character vector, and only these packages will be listed.

Details

Differences with utils::installed.packages():

Encodings

parse_installed() always returns its result in UTF-8 encoding. It uses the Encoding fields in the DESCRIPTION files to learn their encodings. parse_installed() does not check that an UTF-8 file has a valid encoding. If it fails to convert a string to UTF-8 from another declared encoding, then it leaves it as "bytes" encoded, without a warning.

Errors

pkgcache silently ignores files and directories inside the library directory.

The result also omits broken package installations. These include

These errors are reported via a condition with class pkgcache_broken_install. The condition has an errors entry, which is a data frame with columns

If you intend to handle broken package installation, you need to catch this condition with withCallingHandlers().


Parse a repository metadata ⁠PACAKGES*⁠ file

Description

Parse a repository metadata ⁠PACAKGES*⁠ file

Usage

parse_packages(path, type = NULL)

Arguments

path

Path to the ⁠PACKAGES*⁠ file.

type

Type of the file. By default it is determined automatically. Types:

  • uncompressed,

  • gzip compressed,

  • bzip2 compressed,

  • xz compressed.

  • rds, an RDS file, which will be read using base::readRDS().

Details

Non-existent, unreadable or corrupt PACKAGES files with trigger an error.

⁠PACKAGES*⁠ files do not usually declare an encoding, but nevertheless parse_packages() works correctly if they do.

Value

A data frame, with all columns from the file at path.

Note

parse_packages() cannot currently read files that have very many different fields (many columns in the result data frame). The current limit is 1000. Typical PACKAGES files contain less than 20 field types.


Functions to query and manipulate the package cache

Description

pkg_cache_summary() returns a short summary of the state of the cache, e.g. the number of files and their total size. It returns a named list.

Usage

pkg_cache_summary(cachepath = NULL)

pkg_cache_list(cachepath = NULL)

pkg_cache_find(cachepath = NULL, ...)

pkg_cache_get_file(cachepath = NULL, target, ...)

pkg_cache_delete_files(cachepath = NULL, ...)

pkg_cache_add_file(cachepath = NULL, file, relpath = dirname(file), ...)

Arguments

cachepath

Path of the cache. By default the cache directory is in pkgcache, within the user's cache directory. See tools::R_user_dir().

...

Extra named arguments to select the package file.

target

Path where the selected file is copied.

file

File to add.

relpath

The relative path of the file within the cache.

See Also

The package_cache R6 class for a more flexible API.

Examples


pkg_cache_summary()
pkg_cache_list()
pkg_cache_find(package = "forecast")
tmp <- tempfile()
pkg_cache_get_file(target = tmp, package = "forecast", version = "8.10")
pkg_cache_delete_files(package = "forecast")


Does PPM build binary packages for the current platform?

Description

Does PPM build binary packages for the current platform?

Usage

ppm_has_binaries()

Value

TRUE or FALSE.

See Also

The 'pkgcache and Posit Package Manager on Linux' article at https://r-lib.github.io/pkgcache/dev/.

Other PPM functions: ppm_platforms(), ppm_r_versions(), ppm_repo_url(), ppm_snapshots()

Examples


current_r_platform()
ppm_has_binaries()


List all platforms supported by Posit Package Manager (PPM)

Description

List all platforms supported by Posit Package Manager (PPM)

Usage

ppm_platforms()

Value

Data frame with columns:

See Also

The 'pkgcache and Posit Package Manager on Linux' article at https://r-lib.github.io/pkgcache/dev/.

Other PPM functions: ppm_has_binaries(), ppm_r_versions(), ppm_repo_url(), ppm_snapshots()

Examples


ppm_platforms()


List all R versions supported by Posit Package Manager (PPM)

Description

List all R versions supported by Posit Package Manager (PPM)

Usage

ppm_r_versions()

Value

Data frame with columns:

See Also

The 'pkgcache and Posit Package Manager on Linux' article at https://r-lib.github.io/pkgcache/dev/.

Other PPM functions: ppm_has_binaries(), ppm_platforms(), ppm_repo_url(), ppm_snapshots()

Examples


ppm_r_versions()


Returns the current Posit Package Manager (PPM) repository URL

Description

Returns the current Posit Package Manager (PPM) repository URL

Usage

ppm_repo_url()

Details

This URL has the form {base}/{repo}, e.g. ⁠https://packagemanager.posit.co/all⁠.

To configure a hosted PPM instance, set the PKGCACHE_PPM_URL environment variable to the base URL (e.g. ⁠https://packagemanager.posit.co⁠).

To use repo_add() with PPM snapshots, you may also set the PKGCACHE_PPM_REPO environment variable to the name of the default repository.

On Linux, instead of setting these environment variables, you can also add a PPM repository to the repos option, see base::options(). If the environment variables are not set, then ppm_repo_url() will try to extract the PPM base URL and repository name from this option.

If the PKGCACHE_PPM_URL environment variable is not set, and the repos option does not contain a PPM URL (on Linux), then pkgcache uses the public PPM instance at ⁠https://packagemanager.posit.co⁠, with the cran repository.

Value

String scalar, the repository URL of the configured PPM instance. If no PPM instance is configured, then the URL of the Posit Public Package Manager instance. It includes the repository name, e.g. ⁠https://packagemanager.posit.co/all⁠.

See Also

The 'pkgcache and Posit Package Manager on Linux' article at https://r-lib.github.io/pkgcache/dev/.

repo_resolve() and repo_add() to find and configure PPM snapshots.

Other PPM functions: ppm_has_binaries(), ppm_platforms(), ppm_r_versions(), ppm_snapshots()

Examples

ppm_repo_url()

List all available Posit Package Manager (PPM) snapshots

Description

List all available Posit Package Manager (PPM) snapshots

Usage

ppm_snapshots()

Details

The repository URL of a snapshot has the following form on Windows:

{base}/{repo}/{id}

where {base} is the base URL for PPM (see ppm_repo_url()) and {id} is either the date or id of the snapshot, or latest for the latest snapshot. E.g. these are equivalent:

https://packagemanager.posit.co/cran/5
https://packagemanager.posit.co/cran/2017-10-10

On a Linux distribution that has PPM support, the repository URL that contains the binary packages looks like this:

{base}/{repo}/__linux__/{binary_url}/{id}

where {id} is as before, and {binary_url} is a code name for a release of a supported Linux distribution. See the binary_url column of the result of ppm_platforms() for these code names.

Value

Data frame with two columns:

See Also

The 'pkgcache and Posit Package Manager on Linux' article at https://r-lib.github.io/pkgcache/dev/.

Other PPM functions: ppm_has_binaries(), ppm_platforms(), ppm_r_versions(), ppm_repo_url()

Examples


ppm_snapshots()


Authenticated repositories

Description

repo_auth() lists authentication information for all configured repositories.

Usage

repo_auth(
  r_version = getRversion(),
  bioc = TRUE,
  cran_mirror = default_cran_mirror(),
  check_credentials = TRUE
)

Arguments

r_version

R version(s) to use for the Bioconductor repositories, if bioc is TRUE.

bioc

Whether to add Bioconductor repositories, even if they are not configured in the repos option.

cran_mirror

The CRAN mirror to use, see default_cran_mirror().

check_credentials

Whether to check that credentials are available for the authenticated repositories.

Details

pkgcache supports HTTP basic authentication when interacting with CRAN-like repositories. To use authentication, include a username in the repo URL:

https://<username>@<repo-host>/<repo-path>

pkgcache tries to obtain the passwords for the authenticated CRAN-like repos from two sources, in this order:

  1. A "netrc" file. If the NETRC environment variable is set, it should point to a file in "netrc" format. Otherwise pkgcache uses the ⁠~/.netrc⁠ file in the current user's home directory, if it exists. On Windows it also tries the ⁠~/_netrc⁠ file.

  2. The system's credential store, via the keyring package.

See the documentation of libcurl for details about the format of the netrc file.

When looking for the password in the system credential store, pkgcache looks at the following keys, in this order:

https://<username>@repo-host/<repo-path>
https://repo-host/<repo-path>
https://<username>@repo-host
https://repo-host

To add an authenticated repository use repo_add() with the username argument. Alternatively, you can set the repos option directly using base::options() and including the username in the repository URL.

Value

Data frame with columns:


Query and set the list of CRAN-like repositories

Description

pkgcache uses the repos option, see options(). It also automatically uses the current Bioconductor repositories, see bioc_version(). These functions help to query and manipulate the repos option.

Usage

repo_get(
  r_version = getRversion(),
  bioc = TRUE,
  cran_mirror = default_cran_mirror()
)

repo_resolve(spec, username = NULL)

repo_add(..., .list = NULL, username = NULL)

with_repo(repos, expr)

Arguments

r_version

R version(s) to use for the Bioconductor repositories, if bioc is TRUE.

bioc

Whether to add Bioconductor repositories, even if they are not configured in the repos option.

cran_mirror

The CRAN mirror to use, see default_cran_mirror().

spec

A single repository specification, a possibly named character scalar. See details below.

username

User name to set, for authenticated repositories, see repo_auth().

...

Repository specifications. See details below.

.list

List or character vector of repository specifications, see details below.

repos

A list or character vector of repository specifications.

expr

R expression to evaluate.

Details

repo_get() queries the repositories pkgcache uses. It uses the repos option (see options), and also the default Bioconductor repository.

repo_resolve() resolves a single repository specification to a repository URL.

repo_add() adds a new repository to the repos option. (To remove a repository, call option() directly, with the subset that you want to keep.)

with_repo() temporarily adds the repositories in repos, evaluates expr, and then resets the configured repositories.

Value

repo_get() returns a data frame with columns:

repo_resolve() returns a named character vector, with the URL(s) of the repository.

repo_add() returns the same data frame as repo_get(), invisibly.

with_repo() returns the value of expr.

Repository specifications

The format of a repository specification is a named or unnamed character scalar. If the name is missing, pkgcache adds a name automatically. The repository named CRAN is the main CRAN repository, but otherwise names are informational.

Currently supported repository specifications:

Still works for dates starting from 2017-10-10, but now deprecated, because MRAN is discontinued:

Notes:

See Also

Other repository functions: repo_status()

Examples

repo_get()

repo_resolve("PPM@2021-01-21")
#' repo_resolve("PPM@dplyr-1.0.0")
#' repo_resolve("PPM@R-4.0.0")


with_repo(c(CRAN = "PPM@dplyr-1.0.0"), repo_get())
with_repo(c(CRAN = "PPM@dplyr-1.0.0"), meta_cache_list(package = "dplyr"))

with_repo(c(CRAN = "MRAN@2018-06-30"), summary(repo_status()))


Show the status of CRAN-like repositories

Description

It checks the status of the configured or supplied repositories, for the specified platforms and R versions.

Usage

repo_status(
  platforms = default_platforms(),
  r_version = getRversion(),
  bioc = TRUE,
  cran_mirror = default_cran_mirror()
)

Arguments

platforms

Platforms to use, default is default_platforms().

r_version

R version(s) to use, the default is the current R version, via getRversion().

bioc

Whether to add the Bioconductor repositories. If you already configured them via options(repos), then you can set this to FALSE. See bioc_version() for the details about how pkgcache handles Bioconductor repositories.

cran_mirror

The CRAN mirror to use, see default_cran_mirror().

Details

The returned data frame has a summary() method, which shows the same information is a concise table. See examples below.

Value

A data frame that has a row for every repository, on every queried platform and R version. It has these columns:

See Also

Other repository functions: repo_get()

Examples


repo_status()
rst <- repo_status(
  platforms = c("windows", "macos"),
  r_version = c("4.0", "4.1")
)
summary(rst)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.