[SOLVED] List all functions inside a given function

Issue

I would like to map the relations and dependencies of different functions from different scripts.

By now, I´m able to extract all the functions for a given script but I would like to get one level deeper, and try to list all the functions contained in each function.

I´m using the package “NCmisc” and list.functions.in.file function to do the first listing.


rfile <- file.choose() # choose an R script file with functions
list.functions.in.file(rfile) # list all the functions

As a result, it returns the list containing all the functions, but I would like to apply a similar procces to parse all functions inside a given function and complete the “mapping” to that level of detail.

Any ideas? thank you

Solution

There are two possible meanings to “all functions inside a given function”.

  1. If you mean all functions called from a given function, use codetools::findGlobals(fn, merge = FALSE)$functions. This will list everything referenced from within fn that wasn’t defined there.

  2. If you mean all functions defined within a given function, that’s a little harder. I think there are other codetools functions that would let you put this together, but I don’t know the details.

Answered By – user2554330

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *