get_fun_calling: Return the name of a calling function with its context or...

Description Usage Arguments See Also Examples

View source: R/get_fun_calling.r

Description

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.

Usage

1
get_fun_calling(n = 1, showParameters = FALSE)

Arguments

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.

See Also

get_fun_name to retrieve *just* the name of the function, without its context (e.g. "f").

Examples

 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()

envnames documentation built on Dec. 8, 2020, 9:07 a.m.