Learn R Programming

dendrometry (version 0.0.4)

nestedFunBuilder: Create nested data structures with optional function application

Description

Creates nested list structures by grouping data according to specified factors and optionally applying a function to each final subset. This is the main function for creating hierarchical data structures for analysis.

Usage

nestedFunBuilder(data, ..., .fun = identity, .funArgs = list())

Value

A nested list structure where each level corresponds to a factor level. If .fun = identity, returns data subsets. Otherwise, returns the result of applying .fun to each subset.

Arguments

data

a data frame, list, tibble or object coercible by as.data.frame to a data frame containing the variables whose names are given in the factor arguments.

...

character strings specifying the names of grouping variables (factors) in data. The nesting order follows the argument order.

.fun

function to apply to each final data subset. Default is identity which returns the data subset unchanged.

.funArgs

list of additional arguments to pass to .fun.

Details

The function performs the following steps:

  • Validates that all specified factors exist in the data

  • Warns about missing factors and removes them from processing

  • Creates nested subsets using the specified factors

  • Applies the specified function to each final subset

Examples

Run this code
if (FALSE) {
# Create nested data structure
nested_data <- nestedFunBuilder(iris, "Species", "Sepal.Length > 5")

# Apply function to each subset
means <- nestedFunBuilder(iris, "Species",
  .fun = function(data) mean(data$Sepal.Length)
)

# Multiple factors with function
results <- nestedFunBuilder(mydata, "site", "species", "treatment",
  .fun = myAnalysisFunction,
  .funArgs = list(method = "robust")
)
}

Run the code above in your browser using DataLab