R/splicejam-shiny-data.R
get_fn_envir.Rd
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 |
|
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.
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
.
x <- 10; get_fn_envir("x")#> [1] 10test_x <- function(x=NULL, envir=NULL, verbose=FALSE, ...) { get_fn_envir("x", envir, verbose=verbose) } test_x()#> NULL#> NULLtest_x(x=5)#> [1] 5#> [1] 5#> NULL#> NULL# create new environment testenv <- new.env(); testenv$x <- 100; test_x(envir=testenv, verbose=TRUE)#> ## (17:22:59) 27Jul2021: get_fn_envir(): Variable 'x' found in the provided envir#> [1] 100test_x(x=1000, envir=testenv, verbose=TRUE)#> ## (17:22:59) 27Jul2021: get_fn_envir(): Variable 'x' found in parent.frame(1)#> [1] 1000#> ## (17:22:59) 27Jul2021: get_fn_envir(): Variable 'x' found in parent.frame(1)#> [1] 12#> ## (17:22:59) 27Jul2021: get_fn_envir(): Variable 'x' found in the provided envir[[1]]#> [1] 100#> NULL#> ## (17:22:59) 27Jul2021: get_fn_envir(): Variable 'x' found in the provided envir[[1]]#> [1] 10