forestharp-helpers: Forestharp helpers

Description Usage Arguments Details Value Functions Examples

Description

Example of functions that can be directly used on TreeHarp objects individually, and on forestharp objects via fapply.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
count_self_fn(th)

count_lam_fn(th)

count_fn_call(th, pattern, pkg_name)

extract_fn_call(th, pattern, pkg_name)

extract_formal_args(th, fn_name)

extract_assigned_objects(th)

extract_actual_args(th)

detect_growing(th, count = FALSE, within_for = FALSE)

detect_for_in_fn_def(th, fn_name)

count_fn_in_fn(th, fn_name, sub_fn)

detect_fn_call_in_for(th, fn_name)

extract_self_fn(th)

detect_fn_arg(th, fn_name, arg)

detect_nested_for(th)

Arguments

th

A TreeHarp object.

pattern

A regular expression to pick up function names.

pkg_name

The name of a package to match functions with. This should be an exact match for the package name. The package should be attached for this to work. In order to avoid picking up duplicate names, for instance tolower is a function in base R and in ggplot2, run get_libraries on the file as well, and match against it.

fn_name

Function name, as a character string

count

For detect_growing, this is a logical value that indicates if the number of "grow" expressions should be counted and returned, or if just a logical value should be returned.

within_for

If TRUE, only expresssions within a for loop are included.

sub_fn

(For count_fn_in_fn), the function to count (to look for within fn_name).

arg

The argument to check for within fn_name (as a character string).

Details

These are examples of functions that be called on a list of TreeHarp objects, which we refer to as a forestharp object. Such objects are not formally defined yet, but can be created using rmd_to_forestharp or using join_treeharps.

Value

On their own, each of these functions should return a scalar or a 1-dimensional array. When called with fapply, the scalar numerical values can be combined (by taking the sum, any other provided combiner function).

The ultimate idea is that fapply should return a single feature for each rmd file that it is called upon.

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Dummy trees
th1 <- TreeHarp(quote(X <- rnorm(10, mean=0.9, sd=4)), TRUE)
th2 <- TreeHarp(quote(Y <- rbeta(10, shape1=3, shape2=5)), TRUE)
th3 <- TreeHarp(quote(fn1 <- function(x) x + 2), TRUE)
th4 <- TreeHarp(quote(df1 <- mutate(df1, new_col=2*old_col)), TRUE)

# Run helpers
count_self_fn(th3)
count_fn_call(th4, pkg_name="dplyr")
count_fn_call(th1, pattern="^r.*")

autoharp documentation built on Nov. 13, 2021, 1:06 a.m.