ReadCodeChunks: Read Knitr Code Chunks

View source: R/ReadCodeChunks.R

ReadCodeChunksR Documentation

Read Knitr Code Chunks

Description

Read knitr code chunks into the current session.

Usage

ReadCodeChunks(path)

Arguments

path

'character' string. Path name of the knitr source document (‘.Rnw’ or ‘.Rmd’), or R code that has been extracted from a knitr source document (‘.R’).

Details

If the source document is ‘.Rnw’ or ‘.Rmd’ the purl function is used to extract the R code. The R code is read into the current session using a chunk separator of the from ## ---- chunk-name (at least four dashes before the chunk name) in the script. Unnamed chunks (that is, chunk-name is missing) will be assigned names like unnamed-chunk-i where i is the chunk number.

Value

A 'list' of length equal to the number of code chunks in path. Each list component is named after its corresponding chunk name (chunk-name). The returned object includes the value of the path argument as an attribute.

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

Examples

file <- system.file("misc/knitr-markdown.Rmd", package = "inlmisc")
chunks <- ReadCodeChunks(file)
print(chunks)
attr(chunks, "path")

txt <- chunks[c("unnamed-chunk-3", "named-chunk-4")]
eval(parse(text = unlist(txt)))


USGS-R/inlmisc documentation built on Sept. 17, 2022, 2:38 a.m.