functionLength: Compute the length or "complexity" of a function

Description Usage Arguments Value Author(s) See Also Examples

Description

This function computes the "length" of the function. This can be the number of top-level expressions in the body or the total number of expressions computed recursively on all of the body.

When working recursively, we can get the total number of expressions or the number for each of the top-level expressions separately as a vector.

Usage

1
functionLength(e, sum = TRUE, recursive = TRUE)

Arguments

e

the function object whose length is of interest. This can also be the name of the function which is then used via get to fetch the function object. Alternatively, this can be an expression which defines a function. This is useful when working with functions in source files.

sum

a logical value indicating whether to cumulate the results from the individual top-level expressions. This is only used when recursive is TRUE.

recursive

a logical value controlling whether we return the number of top-level expressions (FALSE) or recursively examine each of these top-level expressions and compute the number of sub-expressions they contain, and those sub-expressions contain and so on.

Value

An integer vector. If recursive is FALSE, this is a single number giving the number of top-level expressions in the body.

If recursive is TRUE and sum is TRUE, this is the total number of sub-expressions at all levels in the body. If sum is FALSE, the resulting vector has as many elements as there are top-level expressions in the body. The value for each element is the number of recursive sub-expressions for the corresponding top-level expression.

Author(s)

Duncan Temple Lang

See Also

getFunctionLengths

Examples

1
2
3

omegahat/RSourceTools documentation built on May 24, 2019, 1:55 p.m.