-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move functions from main.R to scripts per function
- Loading branch information
Showing
7 changed files
with
70 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# filter_scripts --------------------------------------------------------------- | ||
#' @importFrom kwb.utils matchesCriteria removeEmptyColumns | ||
filter_scripts <- function(scriptInfo, fun.min = 5, epf.min = 10) | ||
{ | ||
criteria <- c(paste("fun >=", fun.min), paste("epf >=", epf.min)) | ||
|
||
scriptInfo <- scriptInfo[kwb.utils::matchesCriteria(scriptInfo, criteria), ] | ||
|
||
kwb.utils::removeEmptyColumns(scriptInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# get_full_function_info ------------------------------------------------------- | ||
|
||
#' Get information on function definitions in parsed R scripts | ||
#' | ||
#' @param trees list of R script parse trees as provided by | ||
#' \code{\link{parse_scripts}} | ||
#' @importFrom kwb.utils moveColumnsToFront rbindAll | ||
#' @export | ||
#' @seealso \code{\link{parse_scripts}} | ||
get_full_function_info <- function(trees) | ||
{ | ||
function_info <- trees %>% | ||
lapply(function(tree) { | ||
tree %>% | ||
get_functions() %>% | ||
lapply(FUN = get_function_info) %>% | ||
kwb.utils::rbindAll() | ||
}) %>% | ||
kwb.utils::rbindAll(nameColumn = "script") | ||
|
||
merge( | ||
x = function_info, | ||
y = multi_defined_functions(function_info), | ||
by = "functionName" | ||
) %>% | ||
kwb.utils::moveColumnsToFront(c("script", "functionName", "n.def")) | ||
} | ||
|
||
# multi_defined_functions ------------------------------------------------------ | ||
multi_defined_functions <- function(functionInfo) | ||
{ | ||
count <- stats::aggregate( | ||
n.def ~ functionName, | ||
cbind(n.def = seq_len(nrow(functionInfo)), functionInfo), | ||
length | ||
) | ||
|
||
count[order(count$n, decreasing = TRUE), ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# merge_function_info ---------------------------------------------------------- | ||
merge_function_info <- function(scriptInfo, functionInfo) | ||
{ | ||
funExpressions <- expressions_per_function(functionInfo) | ||
|
||
merge( | ||
scriptInfo, | ||
funExpressions[, c("script", "epf")], | ||
by = "script", | ||
all.x = TRUE | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.