Description Usage Arguments Value See Also Examples
Return the name of the function that has been called n
levels up from a given function's body.
This function is intended to be called only within a function.
1 | get_fun_name(n = 0)
|
n |
number of levels to go up in the calling chain in search of the calling function name.
Defaults to |
A string containing the name of the function that has been called n
levels up
from the function calling get_env_name
. The function name is returned without context,
that is the enclosing environment of the function is not part of the returned value.
(e.g. if the function is env1$f
or env1$env2$f
only "f"
will be returned).
get_fun_calling to retrieve the name of the function with its context (e.g. "env1$f"
).
1 2 3 4 5 6 7 8 9 | # Show the name of the active function
f <- function() { cat("We are in function:", get_fun_name(), "\n") }
f()
# Show the name of the calling function
f <- function(x) { cat("Calling function name is:", get_fun_name(1), "\n") }
env1 <- new.env()
with(env1, g <- function() { f(3) })
env1$g()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.