Skip to content

Commit

Permalink
add include_functions fn to pass params to typetracer call for #76
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Aug 26, 2022
1 parent f6ec03a commit 2c7dd80
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: autotest
Title: Automatic Package Testing
Version: 0.0.2.197
Version: 0.0.2.198
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")),
Expand Down
35 changes: 30 additions & 5 deletions R/typetrace-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ autotest_trace_package <- function (package,
package <- dot_to_package (package)
pkg_name <- preload_package (package)

exclude <- exclude_functions (package, functions, exclude)
if (!is.null (exclude)) {
functions <- ls (paste0 ("package:", pkg_name))
functions <- functions [which (!functions %in% exclude)]
}
functions <- include_functions (package, functions, exclude)

Sys.setenv ("TYPETRACER_LEAVE_TRACES" = "true")
if (pkg_name != package) {
Expand Down Expand Up @@ -49,6 +45,35 @@ autotest_trace_package <- function (package,
return (trace_files)
}

# combine lists of `functions` to include and `exclude` into single vector
include_functions <- function (package, functions = NULL, exclude = NULL) {

fns <- m_get_pkg_functions (package)

err_chk <- function (fn_arg, fns, package) {
if (!all (fn_arg %in% fns)) {
fn_arg <- fn_arg [which (!fn_arg %in% fns)]
stop ("The following functions are not in the namespace of ",
"package:", package, ": [",
paste0 (fn_arg, collapse = ", "), "]",
call. = FALSE)
}
}

if (!is.null (functions)) {

err_chk (functions, fns, package)
fns <- fns [which (fns %in% functions)]

} else if (!is.null (exclude)) {

err_chk (exclude, fns, package)
fns <- fns [which (!fns %in% exclude)]
}

return (fns)
}

#' Get all (unique) parameter names from all traced functions.
#'
#' @param traces Result of 'typetracer::trace_package()' call.
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/ropensci-review-tools/autotest",
"issueTracker": "https://github.com/ropensci-review-tools/autotest/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.0.2.197",
"version": "0.0.2.198",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit 2c7dd80

Please sign in to comment.