R/get_package_function_usage.R
get_package_function_usage.Rd
How Often Are the Functions of a Package Used?
get_package_function_usage(tree, package, simple = FALSE, by_script = FALSE)
parse tree as returned by parse_scripts
name of the package (must be installed)
if TRUE
, a simple approach using a simple regular
expression is used. This approach is fast but not correct as it e.g. counts
function calls that are commented out or even string expressions that just
look like function calls. Leaving this argument to its default,
FALSE
, will return only real function calls by evaluating the full
structure of parse tree.
if TRUE
the functions are counted and returned by
script, otherwise they are counted over all scripts
data frame with columns name
(name of the function),
prefixed
(number of function calls prefixed with <package>::
or <package>:::
), non_prefixed
(number of function calls
that are not prefixed with the package name) and total
(total
number of function calls)
# Read all scripts that are provided in the kwb.fakin package
tree <- kwb.code::parse_scripts(root = system.file(package = "kwb.fakin"))
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/example_sizeable_sankey.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/create_treemaps.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/extract_properties.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/paths_to_treenodes.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/paths_to_treenodes_2.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/plot_folder_depths.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/read_different_path_files.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/test_networkD3.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/test_package.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/test_plot_files_in_depth.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/test_reporting.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/test_splitting_paths.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/test_treemap.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/use_pathlist_class.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/write_example_file_info.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/scripts/write_file_property_availability.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/testcalls_1.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/testcalls_2.R ... ok. (0.00s)
#> Reading /Users/runner/work/_temp/Library/kwb.fakin/extdata/testcalls_3.R ... ok. (0.00s)
# Check which functions from kwb.utils are used and how often
get_package_function_usage(tree, package = "kwb.utils")
#> package name count explicit implicit
#> 1 kwb.utils selectElements 8 8 0
#> 2 kwb.utils catAndRun 7 7 0
#> 3 kwb.utils catIf 7 7 0
#> 4 kwb.utils safePath 7 1 6
#> 5 kwb.utils desktop 6 2 4
#> 6 kwb.utils selectColumns 6 6 0
#> 7 kwb.utils getAttribute 5 5 0
#> 8 kwb.utils catLines 3 1 2
#> 9 kwb.utils noFactorDataFrame 3 3 0
#> 10 kwb.utils asColumnList 2 2 0
#> 11 kwb.utils asNoFactorDataFrame 2 2 0
#> 12 kwb.utils headtail 2 2 0
#> 13 kwb.utils loadObject 2 2 0
#> 14 kwb.utils assignPackageObjects 1 1 0
#> 15 kwb.utils collapsed 1 1 0
#> 16 kwb.utils defaultIfNULL 1 1 0
#> 17 kwb.utils excludeNULL 1 1 0
#> 18 kwb.utils extractSubstring 1 1 0
#> 19 kwb.utils fileExtension 1 1 0
#> 20 kwb.utils hsOpenWindowsExplorer 1 1 0
#> 21 kwb.utils isNaOrEmpty 1 1 0
#> 22 kwb.utils makeUnique 1 1 0
#> 23 kwb.utils percentage 1 1 0
#> 24 kwb.utils rbindAll 1 1 0
#> 25 kwb.utils removeExtension 1 1 0
#> 26 kwb.utils resetRowNames 1 1 0
#> 27 kwb.utils stopIfNotMatrix 1 1 0
#> 28 kwb.utils toKeysAndValues 1 1 0
#> 29 kwb.utils user 1 1 0
# Hm, this does not seem to be the whole truth...