DESIGN: Accessing RSP preprocessing variables from the generated script/code
Opened this issue · 0 comments
Question
Should an RSP preprocessing variable be accessible from R (or whatever language is evaluated)? If so, how? For instance, assume we have the following:
<%@string name="foo"%>
If not, then today's implementation needs to be updated, because currently such variables are visible to R (see below).
Immediately/automatically accessible
Should the name
variable simply be assigned to an/the R environment such that it is accessible from as:
RSP variable 'name': <%= name %>
This is how it works today. More precisely, RSP preprocessing variables are assigned "as is" to the environment in which RSP is evaluated (typically the parent=global environment).
A slightly safer approach is to create a separate environment for RSP variable and add/attach this environment to the search path, e.g.
rsp_var_env <- function(name="RSP preprocessing variables") {
pos <- match(name, table=search())
if (is.na(pos)) {
env <- new.env()
attach(env, name=name)
pos <- match(name, table=search())
}
pos.to.env(pos)
} # rsp_var_env()
assign("name", "foo", envir=rsp_var_env(), inherits=FALSE)
Since this environment is on the search path, it should be reachable by all environment that (explicitly or implicitly) links to globalenv()
.