taxon_rank: Taxon rank class

View source: R/taxon_rank.R

taxon_rankR Documentation

Taxon rank class

Description

\Sexpr[results=rd, stage=render]{taxa:::lifecycle("maturing")}

Used to store taxon ranks, possibly associated with a taxonomy database. This is typically used to store taxon ranks in taxon objects.

Usage

taxon_rank(
  rank = character(),
  .names = NULL,
  levels = NULL,
  guess_order = TRUE
)

Arguments

rank

Zero or more taxonomic rank names. Inputs will be transformed to a character vector.

.names

The names of the vector

levels

A named numeric vector indicating the names and orders of possible taxonomic ranks. Higher numbers indicate for fine-scale groupings. Ranks of unknown order can be indicated with NA instead of a number.

guess_order

If TRUE and no rank order is given using numbers, try to guess order based on rank names.

Value

An S3 object of class taxa_taxon_rank

See Also

Other classes: [.taxa_classification(), classification(), taxon_authority(), taxon_db(), taxon_id(), taxon()

Examples


# Making new objects
x <- taxon_rank(c('species', 'species', 'phylum', 'family'))

# Specifiying level order
taxon_rank(c('A', 'B', 'C', 'D', 'A', 'D', 'D'),
           levels = c('D', 'C', 'B', 'A'))
taxon_rank(c('A', 'B', 'C', 'D', 'A', 'D', 'D'),
           levels = c(D = NA, A = 10, B = 20, C = 30))
names(x) <- c('a', 'b', 'c', 'd')

# Manipulating objects
as.character(x)
as.factor(x)
as.ordered(x)
x[2:3]
x[x > 'family'] <- taxon_rank('unknown')
x[1] <- taxon_rank('order')
x['b']
x['b'] <- 'order'

# Using as columns in tables
tibble::tibble(x = x, y = 1:4)
data.frame(x = x, y = 1:4)

# Converting to tables
tibble::as_tibble(x)
as_data_frame(x)

# Trying to add an unknown level as a character causes an error
#x[2] <- 'superkingdom'

# But you can add a new level using taxon_rank objects
x[2] <- taxon_rank('superkingdom')


taxa documentation built on April 12, 2022, 9:06 a.m.