An example for purl()

The function purl() can be used to extract code chunks from a document.

1+1
strsplit('hello world', ' ')

A second chunk.

if (FALSE) plot(1:10)

When we do not evaluate a chunk, the code from purl() will be commented out.

paste(letters, collapse = '|')
if (1 == 1) {
  'Awesome!'
}

If one chunk should not be included in the results from purl(), just use the chunk option purl = FALSE:

# we do not like significance stars!
options(stringsAsFactors = FALSE, show.signif.stars = FALSE)

When a code chunk is supposed to error, use error = TRUE, and purl() will wrap the code in try():

1 + 'a'

That is it.



Try the parsermd package in your browser

Any scripts or data that you put into this service are public.

parsermd documentation built on Aug. 21, 2025, 5:27 p.m.