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. |
modified strings
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.
x <- 7 sinterp("x is .(x), x+1 is .(x+1)\n.(x) is odd is .(x%%2 == 1)")#> [1] "x is 7, x+1 is 8\n7 is odd is TRUE"# 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}))")#> [1] "sin(x*(x+1)) is -0.521551002086912"# 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:]]?$"))#> [1] "x is 7, x+1 is 8\n7 is odd is TRUE"