This is not at all comprehensive, and very hacky, but might be OK if you just need to find functions which are called within the script using parentheses. With your script saved in script.R:
library(tidyverse)
random_script <- read_file("script.R")
strings_matching_open_paren_pattern <- random_script %>%
str_extract_all("[:graph:]*\\(", simplify = FALSE) %>% # e.g. 'c(', 'data.frame('
`[[`(1) %>%
str_remove_all("\\(") %>%
unique()
matched_functions <- strings_matching_open_paren_pattern %>%
map(findFunction) %>%
setNames(strings_matching_open_paren_pattern)
Assumptions:
- All functions are called with open parentheses, so for example this won't pick up the
+ or %in% or [[ functions
- No spaces between function name and open parenthesis (e.g. per tidyverse style guide)
- All function names match the
[:graph:]* regex and everything matching that regex is a function name
The result might end up containing some junk and, depending on how big your script is, you might want to finesse the matched_functions list a bit. Let me know if this helps!