taxa (version 0.3.2)

leaves_apply: Apply function to leaves of each taxon

Description

Apply a function to the leaves of each taxon. This is similar to using leaves() with lapply() or sapply().

obj$leaves_apply(func, subset = NULL, recursive = TRUE,
  simplify = FALSE, value = "taxon_indexes", ...)
leaves_apply(obj, func, subset = NULL, recursive = TRUE,
  simplify = FALSE, value = "taxon_indexes", ...)

Arguments

obj

The taxonomy() or taxmap() object containing taxon information to be queried.

func

(function) The function to apply.

subset

Taxon IDs, TRUE/FALSE vector, or taxon indexes to use. Default: All taxa in obj will be used. Any variable name that appears in all_names() can be used as if it was a vector on its own.

recursive

(logical or numeric) If FALSE, only return the leaves if they occur one rank below the target taxa. If TRUE, return all of the leaves for each taxon. Positive numbers indicate the number of recursions (i.e. number of ranks below the target taxon to return). 1 is equivalent to FALSE. Negative numbers are equivalent to TRUE.

simplify

(logical) If TRUE, then combine all the results into a single vector of unique values.

value

What data to give to the function. Any result of all_names(obj) can be used, but it usually only makes sense to use data that has an associated taxon id.

...

Extra arguments are passed to the function func.

Examples

Run this code
# NOT RUN {
# Count number of leaves under each taxon or its subtaxa
leaves_apply(ex_taxmap, length)

# Count number of leaves under each taxon
leaves_apply(ex_taxmap, length, recursive = FALSE)

# Converting output of leaves to upper case
leaves_apply(ex_taxmap, value = "taxon_names", toupper)

# Passing arguments to the function
leaves_apply(ex_taxmap, value = "taxon_names", paste0, collapse = ", ")

# }

Run the code above in your browser using DataLab