View source: R/splicejam-shiny-data.R
get_fn_envir | R Documentation |
Get value from function call or specific environment in that order
get_fn_envir(x, envir = NULL, verbose = FALSE, ...)
x |
|
envir |
|
verbose |
|
... |
additional arguments are ignored. |
assign_to_envir |
|
This function is a helper function intended to return a variable value, if it exists and is not NULL, by searching these locations in order:
The calling function, which is the environment of the
function that called get_fn_envir()
.
The environment or environments provided in envir
.
It returns NULL
if the previous steps do not find
the object named by x
.
object represented by variable name given in x
from either
the calling function, or the environment envir
, or NULL
if not defined in either case.
x <- 10;
get_fn_envir("x")
test_x <- function(x=NULL, envir=NULL, verbose=FALSE, ...) {
get_fn_envir("x", envir, verbose=verbose)
}
test_x()
test_x(envir=globalenv())
test_x(x=5)
test_x(x=5, envir=globalenv())
test_x(x=NULL, envir=globalenv())
test_x(envir=globalenv())
# create new environment
testenv <- new.env();
testenv$x <- 100;
test_x(envir=testenv, verbose=TRUE)
test_x(x=1000, envir=testenv, verbose=TRUE)
# search testenv then globalenv()
test_x(x=12, envir=c(testenv, globalenv()), verbose=TRUE)
test_x(envir=c(testenv, globalenv()), verbose=TRUE)
testenv$x <- NULL;
test_x(envir=c(testenv, globalenv()), verbose=TRUE)
rm("x", envir=testenv);
test_x(envir=c(testenv, globalenv()), verbose=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.