View source: R/extractFromPackage.R
extractFromPackage | R Documentation |
Extract and compile Rmarkdown files from a “donor” package's installation directory, extracting cached objects from the subsequent knitr cache.
extractFromPackage(
rmd.name,
...,
package,
envir = parent.frame(1),
src.name = "book",
work.dir = bookCache(package)
)
rmd.name |
String containing the path to the donor Rmarkdown file, relative to |
..., envir |
Further arguments to pass to |
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. |
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).
A NULL
is invisibly returned.
Objects are created in envir
and a code chunk is printed; see extractCached
for more details.
Aaron Lun
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.