Curate File Collections

knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE
)

Ideally, file collections are generated by passing proper file specifications in a single call to collate(). In reality, post-processing of the file collection objects is sometimes needed. Thus, we support a selected number of file collection operations.

Merge file collections

You can merge file collections after they are collated. This operation returns the union of the files.

library("pkglite")
pkg <- system.file("examples/pkg1/", package = "pkglite")

fc <- merge(
  pkg %>% collate(file_root_core()),
  pkg %>% collate(file_r()),
  pkg %>% collate(file_r(), file_man())
)

fc

By design, one file collection object only stores metadata of files from a single package. Therefore, merging file collections from different packages will result in an error.

Prune file collections

To remove files from a file collection, use prune():

fc %>% prune(path = c("NEWS.md", "man/figures/logo.png"))

Only the files matching the exact relative path(s) will be removed.

The prune operation is type-stable. If all files in a file collection are removed, an empty file collection is returned so that it can still be merged with the other file collections.

pkg %>%
  collate(file_data()) %>%
  prune(path = "data/dataset.rda")

Sanitize file collections

A file collection might contain files that should almost always be excluded, such as the files defined in pattern_file_sanitize():

pattern_file_sanitize()

You can use sanitize() to remove such files (if any) from a file collection:

fc %>% sanitize()


Try the pkglite package in your browser

Any scripts or data that you put into this service are public.

pkglite documentation built on Aug. 29, 2022, 1:05 a.m.