es: Expression substitution

Description Usage Arguments Details Value See Also Examples

View source: R/es.R

Description

Evaluate R expressions and substitute their values into one or more strings.

Usage

1
es(text, round = NULL, signif = NULL, envir = parent.frame())

Arguments

text

A vector of strings to substitute into.

round

NULL or a single integer, giving the number of decimal digits for rounding numeric expressions. This argument takes priority over signif.

signif

NULL or a single integer, giving the number of significant decimal digits to use for numeric expressions. The round argument takes priority over this one, and will be used if not NULL.

envir

The environment to evaluate expressions in.

Details

Each part of the string surrounded by "#{}" is extracted, evaluated as R code in the specified environment, and then its value is substituted back into the string. The literal string "#{}" can be obtained by escaping the hash character, viz. "\\#{}". The block may contain multiple R expressions, separated by semicolons, but may not contain additional braces.

Value

The final strings, with expression values substituted into them.

See Also

ore.subst

Examples

1
2
3
4
es("pi is #{pi}")
es("pi is \\#{pi}")
es("The square-root of pi is approximately #{sqrt(pi)}", signif=4)
es("1/(1+x) for x=3 is #{x <- 3; 1/(1+x)}")

Example output

[1] "pi is 3.14159265358979"
[1] "pi is #{pi}"
[1] "The square-root of pi is approximately 1.772"
[1] "1/(1+x) for x=3 is 0.25"

ore documentation built on Aug. 30, 2018, 9:05 a.m.