View source: R/string_interpolation.R
sinterp | R Documentation |
String interpolation using bquote
-stype .() notation. Pure R, no C/C++ code called.
sinterp(
str,
...,
envir = parent.frame(),
enclos = parent.frame(),
match_pattern = "\\.\\((([^()]+)|(\\([^()]*\\)))+\\)",
removal_patterns = c("^\\.\\(", "\\)$")
)
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. |
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.
modified strings
strsplit_capture
, si
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:]]?$"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.