Skip to contents

How Often Are the Functions of a Package Used?

Usage

get_package_function_usage(tree, package, simple = FALSE, by_script = FALSE)

Arguments

tree

parse tree as returned by parse_scripts

package

name of the package (must be installed)

simple

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.

by_script

if TRUE the functions are counted and returned by script, otherwise they are counted over all scripts

Value

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)

Examples

# Read all scripts that are provided in the kwb.fakin package
tree <- kwb.code::parse_scripts(root = system.file(package = "kwb.fakin"))

# Check which functions from kwb.utils are used and how often
get_package_function_usage(tree, package = "kwb.utils")
#> Warning: Unknown or uninitialised column: `name`.
#> # A tibble: 0 × 1
#> # ℹ 1 variable: package <chr>

# Hm, this does not seem to be the whole truth...