Get ids of descendants of some taxa

descendants(taxon_ids, taxo, n = Inf)

Arguments

taxon_ids

internal, numeric ids of the taxa.

taxo

a taxonomy data.frame, typically from extract_taxo().

n

maximum number of levels to look down; n=1 gives the direct children, n=2 gives children and grand-children, etc.

Value

A vector of taxonomic ids containing the input taxon_ids and all their descendants.

Details

Even with n=1, the function is different from children() because it returns all unique children for all elements of taxon_ids, not one vector of children per element.

See also

Other taxonomy-related functions: ancestors(), as.taxo(), children(), extract_taxo(), is_leaf(), lineage(), parent(), taxo_id(), taxo_name()

Examples

print(as.Node(taxo), "id")
#> levelName id #> 1 # NA #> 2 °--living 1 #> 3 ¦--fish 2 #> 4 ¦ °--egg 4 #> 5 °--mollusc 3 #> 6 ¦--snail 5 #> 7 ¦ °--egg 7 #> 8 °--squid 6
descendants(3, taxo)
#> [1] 3 5 6 7
descendants(1, taxo)
#> [1] 1 2 3 4 5 6 7
descendants(c(2,5), taxo)
#> [1] 2 5 4 7
descendants(7, taxo)
#> [1] 7
descendants(NA, taxo)
#> [1] NA
descendants(1, taxo, n=1)
#> [1] 1 2 3
descendants(1, taxo, n=2)
#> [1] 1 2 3 4 5 6
descendants(1, taxo, n=3)
#> [1] 1 2 3 4 5 6 7
descendants(1, taxo, n=10)
#> [1] 1 2 3 4 5 6 7
# NB: descendants(5:6, taxo, n=1)
#> [1] 5 6 7
children(5:6, taxo)
#> [[1]] #> [1] 7 #> #> [[2]] #> numeric(0) #>