-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetImports.R
42 lines (34 loc) · 1.35 KB
/
getImports.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fps = dir(path = ".", pattern = "*.R$", recursive = TRUE, full.names = TRUE )
pattern = ".* ([[:alpha:]]*)\\(.*"
functionList = data.frame("filename"=character(), "func"=as.character(), "matchFun"=character(), stringsAsFactors = F)
options(stringsAsFactors = FALSE)
rn = 0
for (fp in fps) {
print (fp)
getImports(fp)
}
uniqFuncs = unique(functionList[functionList$filename=="./server.R" & !functionList$matchFun == "", ])
getImports <- function(fp) {
require(dplyr)
options(stringsAsFactors = FALSE)
pattern = ".* ([[:alpha:]]*)\\(.*"
functionList = data.frame("filename"=character(), "func"=as.character(), "matchFun"=character(), stringsAsFactors = F)
for (ln in readLines(fp)){
if (length(grep(pattern, ln)) > 0) {
mt = gsub (pattern, "\\1", ln)
matFun = tryCatch(match.fun(mt), error = function(e){})
if (nchar(mt) > 0) {
# print(c(fp, mt, environmentName(environment(matFun))))
functionList = rbind(functionList, c(fp, mt, environmentName(environment(matFun))))
}
}
}
colnames(functionList) = c("filename", "func", "matchFun")
uniqFuncs = unique(functionList[!functionList$matchFun == "", ])
uniqFuncs %>% dplyr::group_by(matchFun) %>%
dplyr::mutate(allFunc = paste0(func, collapse = " ")) %>%
select(filename, matchFun, allFunc) %>%
unique %>%
print
print(uniqFuncs)
}