scrapeReferences: Scrape references from a 'bookdown' directory

View source: R/scrapeReferences.R

scrapeReferencesR Documentation

Scrape references from a bookdown directory

Description

Scrape references to sections and figures from all Rmarkdown files in a bookdown directory.

Usage

scrapeReferences(dir, input = "index.Rmd", workdir = tempfile(), clean = TRUE)

Arguments

dir

String containing a path to a bookdown-containing directory.

input

String containing the name of the file to use in the render_book statement.

workdir

String containing a path to a working directory to use to store bits and pieces.

clean

Logical scalar indicating whether the working directory should be removed upon function completion.

Details

This function works by performing a quick dummy compilation of the book, turning off all evaluations with a global eval=FALSE. It then trawls the set of newly created HTML files, pulling out the section/figure identifiers and collating them into a data.frame.

The goal is to facilitate convenient linking between books by automatically filling in the file and text for a given link. Packages that deploy books should run this in their configure scripts to obtain a reference mapping that they can serve to other packages via link.

Extraction of the figure text assumes that the figure prefix ends with a non-numeric character, e.g., "Figure " or "Figure S".

Value

A data.frame where each row corresponds to a reference. It has id, the name of the reference; file, the compiled HTML file that the reference comes from; and text, the text to be associated with that reference.

Author(s)

Aaron Lun

See Also

link, to create links given a package name and identifier.

Examples

book.dir <- system.file("example", package="rebook")
df <- scrapeReferences(book.dir)
df

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