extractFromPackage: Extract cached objects from package's Rmarkdown files

View source: R/extractFromPackage.R

extractFromPackageR Documentation

Extract cached objects from package's Rmarkdown files

Description

Extract and compile Rmarkdown files from a “donor” package's installation directory, extracting cached objects from the subsequent knitr cache.

Usage

extractFromPackage(
  rmd.name,
  ...,
  package,
  envir = parent.frame(1),
  src.name = "book",
  work.dir = bookCache(package)
)

Arguments

rmd.name

String containing the path to the donor Rmarkdown file, relative to work.

..., envir

Further arguments to pass to extractCached.

package

String containing the name of the donor package.

src.name

String containing the name or relative path of the subdirectory in the donor package's installation directory that contains all the Rmarkdown files.

work.dir

String containing the path to a versioned cache directory to hold the contents of donor book, see the dir.expiry package for details.

Details

This function assumes that all potential donor Rmarkdown files for package are present in the directory src.name. It copies the contents of src.name into work.dir and calls extractCached on the rmd.name inside. The desired objects are then extracted from the subsequent knitr cache.

The work.dir directory should be set to a persistent cache to enable greater re-use of the cache across calls and R sessions. Indeed, the default here is the same as that used by preCompileBook, so we can avoid recopmilation if the donor book has already been compiled via the latter function. This function will respect any global locks imposed by other functions in the process of performing the copy (or other rearrangements).

Value

A NULL is invisibly returned. Objects are created in envir and a code chunk is printed; see extractCached for more details.

Author(s)

Aaron Lun

Examples

# Only specifyin 'work.dir' here for demonstration purposes.
# For actual use, just leave it as the default.
tmp <- file.path(tempfile(), "1.0.0")

extractFromPackage("test.Rmd", chunk="ghidorah-1964", src.name="example",
    objects="godzilla", package="rebook", work.dir=tmp)

list.files(tmp)
godzilla


LTLA/rebook documentation built on June 5, 2023, 6:24 p.m.