Say I have some function, f:
f <- function() {
print(sys.calls())
}
Say I have two additional functions,
g <- function() {
f()
}
h <- function() {
f()
}
Calling these functions result in:
> g()
[[1]]
g()
[[2]]
f()
> h()
[[1]]
h()
[[2]]
f()
Assuming that
- None of the functions are further modified or overwritten,
- The only places where
fis ever called is insidegorh.
How reliable/stable/confident can I be that f() will always appear immediately after g() in the call stack, such that I can inside f() check sys.call(-1)[[1]] to determine whether f was called by g or h?
To put it another way, is there some use-pattern I'm missing where a user would do something that would insert another call in the stack between the call to g or h, and the call to f?