compileChapter: Compile a Rmarkdown file

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/compileChapter.R

Description

Compile a Rmarkdown file - typically a chapter of a book - so that extractCached calls work correctly in other chapters.

Usage

1
compileChapter(path, cache = TRUE)

Arguments

path

String containing a path to an Rmarkdown file.

cache

Logical scalar indicating whether the compilation should be cached.

Details

Compilation is performed in an isolated session using r from the callr package. This ensures that settings from one chapter do not affect the next chapter.

If an error is encountered during compilation of any Rmarkdown file, the standard output of render leading up to the error is printed out before the function exists.

Value

The specified file is (re)compiled to generate the corresponding *_cache directories. NULL is invisibly returned.

Author(s)

Aaron Lun

See Also

extractCached, which calls this function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
tmp <- tempfile(fileext=".Rmd")
write(file=tmp, "```{r, echo=FALSE, results='asis'}
rebook::chapterPreamble()
```

```{r}
rodan <- 1
```")

compileChapter(tmp)

file.exists(sub(".Rmd$", ".html", tmp)) # output HTML exists.
file.exists(sub(".Rmd$", "_cache", tmp)) # output cache exists.
exists("rodan") # FALSE

rebook documentation built on Nov. 8, 2020, 4:56 p.m.