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

obj$subtaxa_apply(func, subset = NULL, recursive = TRUE,
  simplify = FALSE, include_input = FALSE, value = "taxon_indexes", ...)
subtaxa_apply(obj, func, subset = NULL, recursive = TRUE,
  simplify = FALSE, include_input = 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 subtaxa one rank below the target taxa. If TRUE, return all the subtaxa of every subtaxa, etc. 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.

include_input

(logical) If TRUE, the input taxa are included in the output

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.

Examples

# Count number of subtaxa in each taxon subtaxa_apply(ex_taxmap, length)
#> $b #> [1] 11 #> #> $c #> [1] 4 #> #> $d #> [1] 4 #> #> $e #> [1] 2 #> #> $f #> [1] 2 #> #> $g #> [1] 3 #> #> $h #> [1] 1 #> #> $i #> [1] 1 #> #> $j #> [1] 1 #> #> $k #> [1] 1 #> #> $l #> [1] 2 #> #> $m #> [1] 0 #> #> $n #> [1] 0 #> #> $o #> [1] 0 #> #> $p #> [1] 0 #> #> $q #> [1] 0 #> #> $r #> [1] 0 #>
# Paste all the subtaxon names for each taxon subtaxa_apply(ex_taxmap, value = "taxon_names", recursive = FALSE, paste0, collapse = ", ")
#> $b #> [1] "Felidae, Notoryctidae, Hominidae" #> #> $c #> [1] "Solanaceae" #> #> $d #> [1] "Panthera, Felis" #> #> $e #> [1] "Notoryctes" #> #> $f #> [1] "homo" #> #> $g #> [1] "Solanum" #> #> $h #> [1] "tigris" #> #> $i #> [1] "catus" #> #> $j #> [1] "typhlops" #> #> $k #> [1] "sapiens" #> #> $l #> [1] "lycopersicum, tuberosum" #> #> $m #> [1] "" #> #> $n #> [1] "" #> #> $o #> [1] "" #> #> $p #> [1] "" #> #> $q #> [1] "" #> #> $r #> [1] "" #>