db.subst | R Documentation |
Simple expression substitution within strings
db.subst(db, text, env = parent.frame())
db |
The database connection. |
env |
The environment in which to perform the substitution. |
txt |
The character string for substitution. |
The input text
is searched for text enclosed
between <
in the calling frame, substituting the value of the last evaluated
expression (if it is a string) in place of the text between delimiters.
The input character string with the values returned from any expressions between braces substituted in place.
Currently delimiters do not nest. That is, the function will stop at the first closing delimiter sequence it finds and try to parse the extracted expression. So "hello, < which will return a parse error.
db = db.open()
greeting = "world!"
db.subst(db, "hello, <% greeting %>!") # => hello, world!!
db.subst(
db
, "hello, <%greeting%> what a grand <%greeting%>"
) # => hello, world! what a grand world!
bar = function() return ("bar")
db.subst(db, "foo <% bar() %>") # => foo bar
db.subst(db, "foo <% bar %>") # => foo # note a trailing space
db.subst(db, "foo <% paste0(deparse(bar), collapse='') %>") # => foo function () return(\"bar\")
db.close(db)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.