Description Usage Arguments See Also Examples
View source: R/get_fun_calling.r
This is a wrapper for get_fun_calling_chain(n)
and returns the name of the calling function
including the environment where it is defined n
levels up. The two pieces of information are
separated by the $
sign.
1 | get_fun_calling(n = 1, showParameters = FALSE)
|
n |
non-negative integer indicating the number of levels to go up from the calling function to retrieve the function in the calling chain. It defaults to 1, which means "return the last function in the calling chain". |
showParameters |
flag indicating whether the parameters of the function call should also be shown in the output. |
get_fun_name to retrieve *just* the name of the function, without its context (e.g. "f"
).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # Prepare environments
env1 <- new.env()
env2 <- new.env()
with(env2, env21 <- new.env())
# Function that shows the names of calling functions in the chain and their environments
f <- function(x) {
cat("Now in function:", get_fun_calling(0), "\n")
cat("\tName of the calling function:", get_fun_calling(), "\n")
cat("\tName of the calling function two levels up:", get_fun_calling(2), "\n")
cat("\tName of the calling function three levels up:", get_fun_calling(3), "\n")
cat("\tName of the calling function four levels up:", get_fun_calling(4), "\n")
}
# Prepare a calling chain
with(env1, g <- function() { f(3) })
with(env2, h <- function() { env1$g() })
with(env2$env21, hh <- function() { env2$h() })
# Run the different functions defined to show the different calling chains
env1$g()
env2$h()
env2$env21$hh()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.