A class containing an ordered list of taxon() objects that represent a hierarchical classification.

hierarchy(..., .list = NULL)

Arguments

...

Any number of object of class Taxon or taxonomic names as character strings

.list

An alternate to the ... input. Any number of object of class taxon() or character vectors in a list. Cannot be used with ....

Value

An R6Class object of class Hierarchy

Details

On initialization, taxa are sorted if they have ranks with a known order.

Methods

pop(rank_names)

Remove Taxon elements by rank name, taxon name or taxon ID. The change happens in place, so you don't need to assign output to a new object. returns self - rank_names (character) a vector of rank names

pick(rank_names)

Select Taxon elements by rank name, taxon name or taxon ID. The change happens in place, so you don't need to assign output to a new object. returns self - rank_names (character) a vector of rank names

See also

Examples

(x <- taxon( name = taxon_name("Poaceae"), rank = taxon_rank("family"), id = taxon_id(4479) ))
#> <Taxon> #> name: Poaceae #> rank: family #> id: 4479 #> authority: none
(y <- taxon( name = taxon_name("Poa"), rank = taxon_rank("genus"), id = taxon_id(4544) ))
#> <Taxon> #> name: Poa #> rank: genus #> id: 4544 #> authority: none
(z <- taxon( name = taxon_name("Poa annua"), rank = taxon_rank("species"), id = taxon_id(93036) ))
#> <Taxon> #> name: Poa annua #> rank: species #> id: 93036 #> authority: none
(res <- hierarchy(z, y, x))
#> <Hierarchy> #> no. taxon's: 3 #> Poaceae / family / 4479 #> Poa / genus / 4544 #> Poa annua / species / 93036
res$taxa
#> [[1]] #> <Taxon> #> name: Poaceae #> rank: family #> id: 4479 #> authority: none #> #> [[2]] #> <Taxon> #> name: Poa #> rank: genus #> id: 4544 #> authority: none #> #> [[3]] #> <Taxon> #> name: Poa annua #> rank: species #> id: 93036 #> authority: none #>
res$ranklist
#> $species #> [1] 220 #> #> $genus #> [1] 180 #> #> $family #> [1] 140 #>
# pop off a rank pop(res, ranks("family"))
#> <Hierarchy> #> no. taxon's: 2 #> Poa / genus / 4544 #> Poa annua / species / 93036
# pick a rank (res <- hierarchy(z, y, x))
#> <Hierarchy> #> no. taxon's: 3 #> Poaceae / family / 4479 #> Poa / genus / 4544 #> Poa annua / species / 93036
pick(res, ranks("family"))
#> <Hierarchy> #> no. taxon's: 1 #> Poaceae / family / 4479
# null taxa x <- taxon(NULL) (res <- hierarchy(x, x, x))
#> <Hierarchy> #> Empty hierarchy
## similar to hierarchy(), but `taxa` slot is not empty