diff --git a/DESCRIPTION b/DESCRIPTION index 4722787..e89b6eb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")), diff --git a/R/typetrace-package.R b/R/typetrace-package.R index f6e927f..f61751a 100644 --- a/R/typetrace-package.R +++ b/R/typetrace-package.R @@ -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) { @@ -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. diff --git a/codemeta.json b/codemeta.json index c73875f..ca557d4 100644 --- a/codemeta.json +++ b/codemeta.json @@ -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",