Learn R Programming

inlmisc (version 0.3.2)

ReadCodeChunks: Read Code Chunks

Description

This function reads knitr code chunks into the current session.

Usage

ReadCodeChunks(path)

Arguments

path

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

Value

Returns a 'list' object 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.

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.

See Also

read_chunk

Examples

Run this code
# NOT RUN {
path <- system.file("doc", "knitr-intro.Rmd", package = "knitr")
chunks <- ReadCodeChunks(path)

attr(chunks, "path")
names(chunks)
chunks[["show-off"]]

eval(parse(text = unlist(chunks[c("show-off", "graphics")])))

# }

Run the code above in your browser using DataLab