sinterp: Dot substitution string interpolation.

View source: R/string_interpolation.R

sinterpR Documentation

Dot substitution string interpolation.

Description

String interpolation using bquote-stype .() notation. Pure R, no C/C++ code called.

Usage

sinterp(
  str,
  ...,
  envir = parent.frame(),
  enclos = parent.frame(),
  match_pattern = "\\.\\((([^()]+)|(\\([^()]*\\)))+\\)",
  removal_patterns = c("^\\.\\(", "\\)$")
)

Arguments

str

charater string(s) to be substituted into

...

force later arguments to bind by name

envir

environemnt to look for values

enclos

enclosing evaluation environment

match_pattern

regexp to find substitution targets.

removal_patterns

regexps to remove markers from substitution targets.

Details

See also https://CRAN.R-project.org/package=R.utils, https://CRAN.R-project.org/package=rprintf, and https://CRAN.R-project.org/package=glue.

Value

modified strings

See Also

strsplit_capture, si

Examples


x <- 7
sinterp("x is .(x), x+1 is .(x+1)\n.(x) is odd is .(x%%2 == 1)")

# Because matching is done by a regular expression we
# can not use arbitrary depths of nested parenthesis inside
# the interpolation region.  The default regexp allows
# one level of nesting (and one can use {} in place
# of parens in many places).
sinterp("sin(x*(x+1)) is .(sin(x*{x+1}))")

# We can also change the delimiters,
# in this case to !! through the first whitespace.
sinterp(c("x is !!x , x+1 is !!x+1 \n!!x  is odd is !!x%%2==1"),
        match_pattern = '!![^[:space:]]+[[:space:]]?',
        removal_patterns = c("^!!", "[[:space:]]?$"))


wrapr documentation built on Aug. 20, 2023, 1:08 a.m.