si | R Documentation |
String interpolation using bquote
-stype .() notation. Pure R, no C/C++ code called.
sinterp
and si
are synonyms.
si(
str,
...,
envir = parent.frame(),
enclos = parent.frame(),
match_pattern = "\\.\\((([^()]+)|(\\([^()]*\\)))+\\)",
removal_patterns = c("^\\.\\(", "\\)$")
)
str |
charater string 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
, sinterp
x <- 7
si("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).
si("sin(x*(x+1)) is .(sin(x*{x+1}))")
# We can also change the delimiters,
# in this case to !! through the first whitespace.
si(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.