3

I have code like this:

f.internal <- function(){
  print("f.internal was called by ...")
}

f.external <- function(){
  f.internal()
}

How to check in R, which of the two functions runs the other function?

Heikki
  • 2,214
  • 19
  • 34
Tomasz
  • 610
  • 4
  • 22
  • 3
    Relevant / Possible duplicate https://stackoverflow.com/questions/44143110/visualizing-r-function-dependencies – zx8754 Dec 11 '17 at 13:45
  • 3
    Another related link https://stackoverflow.com/questions/4795982/generating-a-call-graph-in-r – akrun Dec 11 '17 at 13:47

1 Answers1

0

Write a helper named getCaller(), which uses stop() within a tryCatch to generate a traceback call stack. Using that it can identify the last few calling functions.

Then have f.internal() call the helper to produce the desired output.

J_H
  • 17,926
  • 4
  • 24
  • 44