View source: R/scrapeReferences.R
scrapeReferences | R Documentation |
Scrape references to sections and figures from all Rmarkdown files in a bookdown directory.
scrapeReferences(dir, input = "index.Rmd", workdir = tempfile(), clean = TRUE)
dir |
String containing a path to a bookdown-containing directory. |
input |
String containing the name of the file to use in the |
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. |
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"
.
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.
Aaron Lun
link
, to create links given a package name and identifier.
book.dir <- system.file("example", package="rebook")
df <- scrapeReferences(book.dir)
df
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.