get_package_function_usage: How Often Are the Functions of a Package Used?

View source: R/get_package_function_usage.R

get_package_function_usageR Documentation

How Often Are the Functions of a Package Used?

Description

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")

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

KWB-R/kwb.code documentation built on July 28, 2023, 5:57 p.m.