get_fun_name {envnames} | R Documentation |
Return the name of the current function or a calling function in the chain
Description
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.
Usage
get_fun_name(n = 0)
Arguments
n |
number of levels to go up in the calling chain in search of the calling function name.
Defaults to |
Value
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).
See Also
get_fun_calling to retrieve the name of the function with its context (e.g. "env1$f"
).
Examples
# 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()