sourceRmd: Source the R code from an RMarkdown file

View source: R/utils_sourceRmd.R

sourceRmdR Documentation

Source the R code from an RMarkdown file

Description

Retrieve the R code from an RMarkdown file and source it into a new environment variable. Uses knitr::purl(), which comments-out any chunks that are not meant to be evaluated (i.e., eval = F).

Usage

sourceRmd(path, wd = dirname(path), suppress = T, ...)

Arguments

path

Path to RMarkdown file

wd

Optional working directory to use for script execution. Defaults to the directory containing the RMarkdown file.

suppress

Supress all output from executed code?

...

Arguments passed on to base::source

file

a connection or a character string giving the pathname of the file or URL to read from. "" indicates the connection stdin().

local

TRUE, FALSE or an environment, determining where the parsed expressions are evaluated. FALSE (the default) corresponds to the user's workspace (the global environment) and TRUE to the environment from which source is called.

echo

logical; if TRUE, each expression is printed after parsing, before evaluation.

print.eval

logical; if TRUE, the result of eval(i) is printed for each expression i; defaults to the value of echo.

exprs

for source() and withAutoprint(*, evaluated=TRUE): instead of specifying file, an expression, call, or list of call's, but not an unevaluated “expression”.

for withAutoprint() (with default evaluated=FALSE): one or more unevaluated “expressions”.

spaced

logical indicating if newline (hence empty line) should be printed before each expression (when echo = TRUE).

verbose

if TRUE, more diagnostics (than just echo = TRUE) are printed during parsing and evaluation of input, including extra info for each expression.

prompt.echo

character; gives the prompt to be used if echo = TRUE.

max.deparse.length

integer; is used only if echo is TRUE and gives the maximal number of characters output for the deparse of a single expression.

width.cutoff

integer, passed to deparse() which is used (only) when there are no source references.

deparseCtrl

character vector, passed as control to deparse(), see also .deparseOpts. In R version <= 3.3.x, this was hardcoded to "showAttributes", which is the default currently; deparseCtrl = "all" may be preferable, when strict back compatibility is not of importance.

chdir

logical; if TRUE and file is a pathname, the R working directory is temporarily changed to the directory containing file for evaluating.

encoding

character vector. The encoding(s) to be assumed when file is a character string: see file. A possible value is "unknown" when the encoding is guessed: see the ‘Encodings’ section.

continue.echo

character; gives the prompt to use on continuation lines if echo = TRUE.

skip.echo

integer; how many comment lines at the start of the file to skip if echo = TRUE.

keep.source

logical: should the source formatting be retained when echoing expressions, if possible?

Value

A new environment containing the results of the sourced R code


adamleejohnson/R-ajtools documentation built on April 4, 2022, 7:24 a.m.