Title: | Classes for Storing and Manipulating Taxonomic Data |
---|---|
Description: | Provides classes for storing and manipulating taxonomic data. Most of the classes can be treated like base R vectors (e.g. can be used in tables as columns and can be named). Vectorized classes can store taxon names and authorities, taxon IDs from databases, taxon ranks, and other types of information. More complex classes are provided to store taxonomic trees and user-defined data associated with them. |
Authors: | Scott Chamberlain [aut] , Zachary Foster [aut, cre] |
Maintainer: | Zachary Foster <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.4.3 |
Built: | 2024-11-27 03:23:57 UTC |
Source: | https://github.com/ropensci/taxa |
A wrapper for the base value matching %in% that is used to take into consideration features of the taxa package.
x %in% table
x %in% table
x |
vector or |
table |
vector or |
data.frame
Convert the information in a taxa object to a data.frame
using base R
vectors as columns. Use as_tibble to convert to tibbles.
as_data_frame( x, row.names = NULL, optional = FALSE, ..., stringsAsFactors = FALSE )
as_data_frame( x, row.names = NULL, optional = FALSE, ..., stringsAsFactors = FALSE )
x |
|
row.names |
|
optional |
logical. If |
... |
additional arguments to be passed to or from methods. |
stringsAsFactors |
logical: should the character vector be converted to a factor? |
x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) as_data_frame(x)
x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) as_data_frame(x)
Convert other objects to taxon vectors. Compatible base R vectors can also be converted using the taxon constructor.
as_taxon(x, ...)
as_taxon(x, ...)
x |
An object to be converted to a taxon vector |
... |
Additional parameters. |
# Convert a taxonomy object to a taxon vector x <- taxonomy(taxon(name = c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), rank = c('order', 'family', 'genus', 'species', 'species', 'family', 'genus', 'species'), id = taxon_id(c('33554', '9681', '9688', '9689', '9694', '9632', '9639', '9644'), db = 'ncbi'), auth = c('Bowdich, 1821', 'Fischer de Waldheim, 1817', 'Oken, 1816', 'L., 1758', 'L., 1758', 'Fischer de Waldheim, 1817', 'L., 1758', 'L., 1758')), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) names(x) <- letters[1:8] as_taxon(x) # Convert base R vectors as_taxon(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo')) as_taxon(factor(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo')))
# Convert a taxonomy object to a taxon vector x <- taxonomy(taxon(name = c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), rank = c('order', 'family', 'genus', 'species', 'species', 'family', 'genus', 'species'), id = taxon_id(c('33554', '9681', '9688', '9689', '9694', '9632', '9639', '9644'), db = 'ncbi'), auth = c('Bowdich, 1821', 'Fischer de Waldheim, 1817', 'Oken, 1816', 'L., 1758', 'L., 1758', 'Fischer de Waldheim, 1817', 'L., 1758', 'L., 1758')), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) names(x) <- letters[1:8] as_taxon(x) # Convert base R vectors as_taxon(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo')) as_taxon(factor(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo')))
Used to store classifications in reference to a taxonomic tree.
classification(x = NULL, taxonomy = NULL, .names = NULL)
classification(x = NULL, taxonomy = NULL, .names = NULL)
x |
One of:
|
taxonomy |
A taxonomy object. Only needed if taxon indexes are supplied as the first argument. |
.names |
The names of the vector. |
An S3
object of class taxa_classification
Other classes:
[.taxa_classification()
,
taxon()
,
taxon_authority()
,
taxon_db()
,
taxon_id()
,
taxon_rank()
# Create classification vector with a list x <- classification(list( c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo'), c('Carnivora', 'Felidae', 'Panthera', 'Panthera tigris'), c('Carnivora', 'Ursidae', 'Ursus', 'Ursus arctos'), c('Carnivora', 'Ursidae', 'Ursus', 'Ursus arctos'), c('Carnivora', 'Felidae', 'Panthera', 'Panthera tigris') )) # Create classification vector with indexes and a taxonomy x <- classification(c(3, 4, 4, 5, 5, 6, 8, 8, 2, 5, 6, 2), taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7))) x <- classification(c(3, 4, 4, 5, 5, 6, 8, 8, 2, 5, 6, 2), taxonomy(taxon(name = c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), rank = c('order', 'family', 'genus', 'species', 'species', 'family', 'genus', 'species'), id = taxon_id(c('33554', '9681', '9688', '9689', '9694', '9632', '9639', '9644'), db = 'ncbi'), auth = c('Bowdich, 1821', 'Fischer, 1817', 'Oken, 1816', 'L., 1758', 'L., 1758', 'Fischer, 1817', 'L., 1758', 'L., 1758')), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7))) names(x) <- letters[1:12] # Get parts of the classification vector tax_name(x) tax_rank(x) tax_id(x) tax_db(x) tax_auth(x) tax_author(x) tax_date(x) tax_cite(x) # Manipulate classification vectors x[1:3] x[tax_rank(x) > 'family'] # c(x, x) # x['b'] <- NA is.na(x) # as.data.frame(x) # tibble::as_tibble(x) # Use as columns in tables tibble::tibble(x = x, y = 1:12) data.frame(x = x, y = 1:12)
# Create classification vector with a list x <- classification(list( c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo'), c('Carnivora', 'Felidae', 'Panthera', 'Panthera tigris'), c('Carnivora', 'Ursidae', 'Ursus', 'Ursus arctos'), c('Carnivora', 'Ursidae', 'Ursus', 'Ursus arctos'), c('Carnivora', 'Felidae', 'Panthera', 'Panthera tigris') )) # Create classification vector with indexes and a taxonomy x <- classification(c(3, 4, 4, 5, 5, 6, 8, 8, 2, 5, 6, 2), taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7))) x <- classification(c(3, 4, 4, 5, 5, 6, 8, 8, 2, 5, 6, 2), taxonomy(taxon(name = c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), rank = c('order', 'family', 'genus', 'species', 'species', 'family', 'genus', 'species'), id = taxon_id(c('33554', '9681', '9688', '9689', '9694', '9632', '9639', '9644'), db = 'ncbi'), auth = c('Bowdich, 1821', 'Fischer, 1817', 'Oken, 1816', 'L., 1758', 'L., 1758', 'Fischer, 1817', 'L., 1758', 'L., 1758')), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7))) names(x) <- letters[1:12] # Get parts of the classification vector tax_name(x) tax_rank(x) tax_id(x) tax_db(x) tax_auth(x) tax_author(x) tax_date(x) tax_cite(x) # Manipulate classification vectors x[1:3] x[tax_rank(x) > 'family'] # c(x, x) # x['b'] <- NA is.na(x) # as.data.frame(x) # tibble::as_tibble(x) # Use as columns in tables tibble::tibble(x = x, y = 1:12) data.frame(x = x, y = 1:12)
This defines the valid taxonomic databases that can be used in taxon_db
objects and objects that use taxon_db objects, such as taxon_id and
taxon. db_ref$get
can be used to see information for the databases. Users
can add their own custom databases to the list using db_ref$set
. For each
database the following information is included:
The URL for the website associated with the database
A short description
The regular expression that defines valid taxon IDs
The ranks used in the database if specified
db_ref
db_ref
An object of class list
of length 3.
This code is based on the code handling options in the knitr package.
# List all database definitions db_ref$get() # Get a specific database definition db_ref$get('ncbi') # Add or overwrite a database definition db_ref$set( name = "my_new_database", url = "http://www.my_tax_database.com", desc = "I just made this up", id_regex = ".*" ) # Reset definitions to default values db_ref$reset()
# List all database definitions db_ref$get() # Get a specific database definition db_ref$get('ncbi') # Add or overwrite a database definition db_ref$set( name = "my_new_database", url = "http://www.my_tax_database.com", desc = "I just made this up", id_regex = ".*" ) # Reset definitions to default values db_ref$reset()
Get internodes indexes for each taxon or another per-taxon value. An internode is a taxon with exactly one supertaxon and one subtaxon. These taxa can be removed without losing information on the relationships of the remaining taxa.
internodes(x)
internodes(x)
x |
The object to get internodes for, such as a taxonomy object. |
Other taxonomy functions:
leaves()
,
roots()
,
stems()
,
subtaxa()
,
supertaxa()
Other internode functions:
is_internode()
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) internodes(x)
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) internodes(x)
Check if an object is the classification class
is_classification(x)
is_classification(x)
x |
An object to test |
Check if each taxon is an internode. An internode is a taxon with exactly one supertaxon and one subtaxon. These taxa can be removed without losing information on the relationships of the remaining taxa.
is_internode(x)
is_internode(x)
x |
The object to get internodes for, such as a taxonomy object. |
Other internode functions:
internodes()
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) is_internode(x)
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) is_internode(x)
Check if each taxon is a leaf. A leaf is a taxon with no subtaxa. subtaxa.
is_leaf(x)
is_leaf(x)
x |
The object to get leaves for, such as a taxonomy object |
Other leaf functions:
leaves()
,
n_leaves()
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) is_leaf(x)
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) is_leaf(x)
Check if each taxon is a root. A root is a taxon with no supertaxon.
is_root(x, subset = NULL)
is_root(x, subset = NULL)
x |
An object containing taxonomic relationships, such as taxonomy objects. |
subset |
The subset of the tree to search for roots to that subset. Can be indexes or names. |
Other root functions:
roots()
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) is_root(x) is_root(x, subset = 2:8)
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) is_root(x) is_root(x, subset = 2:8)
Check if each taxon is a stem. A stem is any taxa from a root to the first taxon with multiple subtaxa.
is_stem(x)
is_stem(x)
x |
An object with taxonomic relationships, like taxonomy objects. |
Other stem functions:
stems()
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris'), supertaxa = c(NA, 1, 2, 3, 3)) is_stem(x)
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris'), supertaxa = c(NA, 1, 2, 3, 3)) is_stem(x)
Check if an object is of the taxon class
is_taxon(x)
is_taxon(x)
x |
An object to test |
x <- taxon(c('A', 'B', 'C')) is_taxon(x) is_taxon(1:2)
x <- taxon(c('A', 'B', 'C')) is_taxon(x) is_taxon(1:2)
Check if an object is of the taxon_authority class
is_taxon_authority(x)
is_taxon_authority(x)
x |
An object to test |
x <- taxon_authority(c('Cham. & Schldl.', 'L.'), date = c('1827', '1753')) is_taxon_authority(x) is_taxon_authority(1:3)
x <- taxon_authority(c('Cham. & Schldl.', 'L.'), date = c('1827', '1753')) is_taxon_authority(x) is_taxon_authority(1:3)
Check if an object is of the taxon_db class
is_taxon_db(x)
is_taxon_db(x)
x |
An object to test |
x <- taxon_db(c('ncbi', 'ncbi', 'itis')) is_taxon_db(x) is_taxon_db(1:3)
x <- taxon_db(c('ncbi', 'ncbi', 'itis')) is_taxon_db(x) is_taxon_db(1:3)
Check if an object is of the taxon_id class
is_taxon_id(x)
is_taxon_id(x)
x |
An object to test |
x <- taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi') is_taxon_id(x) is_taxon_id(1:3)
x <- taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi') is_taxon_id(x) is_taxon_id(1:3)
Check if an object is of the taxon_rank class
is_taxon_rank(x)
is_taxon_rank(x)
x |
An object to test |
x <- taxon_rank(c('species', 'species', 'phylum', 'family')) is_taxon_rank(x) is_taxon_rank(1:3)
x <- taxon_rank(c('species', 'species', 'phylum', 'family')) is_taxon_rank(x) is_taxon_rank(1:3)
Check if an object is of the taxonomy class
is_taxonomy(x)
is_taxonomy(x)
x |
An object to test |
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) is_taxonomy(x) is_taxonomy(1:2)
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) is_taxonomy(x) is_taxonomy(1:2)
Get leaves indexes for each taxon or another per-taxon value. Leaves are taxa with no subtaxa.
leaves(x, value = NULL, ...)
leaves(x, value = NULL, ...)
x |
The object to get leaves for, such as a taxonomy object |
value |
Something to return instead of indexes. Must be the same length as the number of taxa. |
... |
Additional arguments. |
Other taxonomy functions:
internodes()
,
roots()
,
stems()
,
subtaxa()
,
supertaxa()
Other leaf functions:
is_leaf()
,
n_leaves()
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) leaves(x) leaves(x, value = tax_name(x))
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) leaves(x) leaves(x, value = tax_name(x))
Get the number of leaves per taxon. A leaf is a taxon with no subtaxa.
n_leaves(x)
n_leaves(x)
x |
The object to get leaves for, such as a taxonomy object |
Other leaf functions:
is_leaf()
,
leaves()
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) n_leaves(x)
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) n_leaves(x)
Get the number of subtaxa per taxon.
n_subtaxa(x, subset = NULL, max_depth = NULL, include = FALSE)
n_subtaxa(x, subset = NULL, max_depth = NULL, include = FALSE)
x |
The object to get subtaxa for, such as a taxonomy object. |
subset |
The subset of the tree to search. Can be indexes or names. |
max_depth |
The number of ranks to traverse. For example, |
include |
If |
Other subtaxa functions:
subtaxa()
# Generate example data x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) # Find number of subtaxa (including subtaxa of subtaxa, etc) n_subtaxa(x) # Find the number of subtaxa one rank below each taxon n_subtaxa(x, max_depth = 1) # Only return data for some taxa (faster than subsetting the whole result) n_subtaxa(x, subset = 1:3)
# Generate example data x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) # Find number of subtaxa (including subtaxa of subtaxa, etc) n_subtaxa(x) # Find the number of subtaxa one rank below each taxon n_subtaxa(x, max_depth = 1) # Only return data for some taxa (faster than subsetting the whole result) n_subtaxa(x, subset = 1:3)
Get the number of supertaxa each taxon is contained in.
n_supertaxa(x, subset = NULL, max_depth = NULL, include = FALSE)
n_supertaxa(x, subset = NULL, max_depth = NULL, include = FALSE)
x |
The object to get supertaxa for, such as a taxonomy object. |
subset |
The subset of the tree to search for roots to that subset. Can be indexes or names. |
max_depth |
The number of levels to traverse. For example, |
include |
If |
Other supertaxa functions:
supertaxa()
# Generate example data x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) # Find number of supertaxa each taxon is contained in n_supertaxa(x) # Only return data for some taxa (faster than subsetting the whole result) n_supertaxa(x, subset = 1:3)
# Generate example data x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) # Find number of supertaxa each taxon is contained in n_supertaxa(x) # Only return data for some taxa (faster than subsetting the whole result) n_supertaxa(x, subset = 1:3)
Get the indexes of root taxa in a taxonomy.
roots(x, subset = NULL)
roots(x, subset = NULL)
x |
An object containing taxonomic relationships, such as taxonomy objects. |
subset |
The subset of the tree to search for roots to that subset. Can be indexes or names. |
Other taxonomy functions:
internodes()
,
leaves()
,
stems()
,
subtaxa()
,
supertaxa()
Other root functions:
is_root()
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) roots(x) roots(x, subset = 2:8)
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) roots(x) roots(x, subset = 2:8)
Get stem indexes for each taxon or another per-taxon value.
stems(x, value = NULL, ...)
stems(x, value = NULL, ...)
x |
An object with taxonomic relationships, like taxonomy objects. |
value |
Something to return instead of indexes. Must be the same length as the number of taxa. |
... |
Additional arguments. |
Other taxonomy functions:
internodes()
,
leaves()
,
roots()
,
subtaxa()
,
supertaxa()
Other stem functions:
is_stem()
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris'), supertaxa = c(NA, 1, 2, 3, 3)) x <- c(x, x) stems(x) stems(x, value = tax_name(x))
x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris'), supertaxa = c(NA, 1, 2, 3, 3)) x <- c(x, x) stems(x) stems(x, value = tax_name(x))
Get subtaxa indexes for each taxon or another per-taxon value. Subtaxa are taxa contained within a taxon.
subtaxa(x, subset = NULL, max_depth = NULL, include = FALSE, value = NULL, ...)
subtaxa(x, subset = NULL, max_depth = NULL, include = FALSE, value = NULL, ...)
x |
The object to get subtaxa for, such as a taxonomy object. |
subset |
The subset of the tree to search. Can be indexes or names. |
max_depth |
The number of ranks to traverse. For example, |
include |
If |
value |
Something to return instead of indexes. Must be the same length as the number of taxa. |
... |
Additional arguments. |
Other taxonomy functions:
internodes()
,
leaves()
,
roots()
,
stems()
,
supertaxa()
Other subtaxa functions:
n_subtaxa()
# Generate example data x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) # The indexes of all subtaxa (with subtaxa of subtaxa, etc) for each taxon subtaxa(x) # The indexes of immediate subtaxa (without subtaxa of subtaxa, etc) for each taxon subtaxa(x, max_depth = 1) # Return something other than index subtaxa(x, value = tax_name(x)) # Include each taxon with its subtaxa subtaxa(x, value = tax_name(x), include = TRUE) # Only return data for some taxa (faster than subsetting the whole result) subtaxa(x, subset = 3)
# Generate example data x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) # The indexes of all subtaxa (with subtaxa of subtaxa, etc) for each taxon subtaxa(x) # The indexes of immediate subtaxa (without subtaxa of subtaxa, etc) for each taxon subtaxa(x, max_depth = 1) # Return something other than index subtaxa(x, value = tax_name(x)) # Include each taxon with its subtaxa subtaxa(x, value = tax_name(x), include = TRUE) # Only return data for some taxa (faster than subsetting the whole result) subtaxa(x, subset = 3)
Get supertaxa indexes for each taxon or another per-taxon value. Supertaxa are taxa a taxon is contained in.
supertaxa( x, subset = NULL, max_depth = NULL, include = FALSE, value = NULL, use_na = FALSE, ... )
supertaxa( x, subset = NULL, max_depth = NULL, include = FALSE, value = NULL, use_na = FALSE, ... )
x |
The object to get supertaxa for, such as a taxonomy object. |
subset |
The subset of the tree to search for roots to that subset. Can be indexes or names. |
max_depth |
The number of levels to traverse. For example, |
include |
If |
value |
Something to return instead of indexes. Must be the same length as the number of taxa. |
use_na |
Add a NA to represent the root of the taxonomy (i.e. no supertaxon) |
... |
Additional arguments. |
Other taxonomy functions:
internodes()
,
leaves()
,
roots()
,
stems()
,
subtaxa()
Other supertaxa functions:
n_supertaxa()
# Generate example data x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) # The indexes of all supertaxa (with supertaxa of supertaxa, etc) for each taxon supertaxa(x) # Return something other than index supertaxa(x, value = tax_name(x)) # Include each taxon with its supertaxa supertaxa(x, value = tax_name(x), include = TRUE) # Only return data for some taxa (faster than subsetting the whole result) supertaxa(x, subset = 3)
# Generate example data x <- taxonomy(c('Carnivora', 'Felidae', 'Panthera', 'Panthera leo', 'Panthera tigris', 'Ursidae', 'Ursus', 'Ursus arctos'), supertaxa = c(NA, 1, 2, 3, 3, 1, 6, 7)) # The indexes of all supertaxa (with supertaxa of supertaxa, etc) for each taxon supertaxa(x) # Return something other than index supertaxa(x, value = tax_name(x)) # Include each taxon with its supertaxa supertaxa(x, value = tax_name(x), include = TRUE) # Only return data for some taxa (faster than subsetting the whole result) supertaxa(x, subset = 3)
Set and get the taxon authorities in objects that have them, such as taxon objects. Note that this sets all the authority information, such as author name, date, and citations. To set or get just one of part of the authorities, use tax_author, tax_date, or tax_cite instead.
## S3 method for class 'taxa_classification' tax_auth(x) ## S3 replacement method for class 'taxa_classification' tax_auth(x) <- value tax_auth(x) tax_auth(x) <- value ## S3 method for class 'taxa_taxon' tax_auth(x) ## S3 replacement method for class 'taxa_taxon' tax_auth(x) <- value ## S3 method for class 'taxa_taxonomy' tax_auth(x) ## S3 replacement method for class 'taxa_taxonomy' tax_auth(x) <- value
## S3 method for class 'taxa_classification' tax_auth(x) ## S3 replacement method for class 'taxa_classification' tax_auth(x) <- value tax_auth(x) tax_auth(x) <- value ## S3 method for class 'taxa_taxon' tax_auth(x) ## S3 replacement method for class 'taxa_taxon' tax_auth(x) <- value ## S3 method for class 'taxa_taxonomy' tax_auth(x) ## S3 replacement method for class 'taxa_taxonomy' tax_auth(x) <- value
x |
An object with taxon authorities. |
value |
The taxon IDs to set. Inputs will be coerced into a taxon_id vector. |
x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) tax_auth(x) tax_auth(x) <- tolower(tax_auth(x)) tax_auth(x)[1] <- 'Billy'
x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) tax_auth(x) tax_auth(x) <- tolower(tax_auth(x)) tax_auth(x)[1] <- 'Billy'
Set and get taxon authors in objects that have them, such as taxon_authority objects.
## S3 method for class 'taxa_classification' tax_author(x) ## S3 replacement method for class 'taxa_classification' tax_author(x) <- value tax_author(x) tax_author(x) <- value ## S3 method for class 'taxa_taxon' tax_author(x) ## S3 replacement method for class 'taxa_taxon' tax_author(x) <- value ## S3 replacement method for class 'taxa_taxon_authority' tax_author(x) <- value ## S3 method for class 'taxa_taxon_authority' tax_author(x) ## S3 method for class 'taxa_taxonomy' tax_author(x) ## S3 replacement method for class 'taxa_taxonomy' tax_author(x) <- value
## S3 method for class 'taxa_classification' tax_author(x) ## S3 replacement method for class 'taxa_classification' tax_author(x) <- value tax_author(x) tax_author(x) <- value ## S3 method for class 'taxa_taxon' tax_author(x) ## S3 replacement method for class 'taxa_taxon' tax_author(x) <- value ## S3 replacement method for class 'taxa_taxon_authority' tax_author(x) <- value ## S3 method for class 'taxa_taxon_authority' tax_author(x) ## S3 method for class 'taxa_taxonomy' tax_author(x) ## S3 replacement method for class 'taxa_taxonomy' tax_author(x) <- value
x |
An object with taxon authors. |
value |
The taxon authors to set. Inputs will be coerced into a character vector. |
x <- taxon_authority(c('Cham. & Schldl.', 'L.'), date = c('1827', '1753')) tax_author(x) tax_author(x)[1] <- "Billy" tax_author(x) <- tolower(tax_author(x))
x <- taxon_authority(c('Cham. & Schldl.', 'L.'), date = c('1827', '1753')) tax_author(x) tax_author(x)[1] <- "Billy" tax_author(x) <- tolower(tax_author(x))
Set and get the taxon authority citations in objects that have them, such as taxon_authority objects.
## S3 method for class 'taxa_classification' tax_cite(x) ## S3 replacement method for class 'taxa_classification' tax_cite(x) <- value tax_cite(x) tax_cite(x) <- value ## S3 method for class 'taxa_taxon' tax_cite(x) ## S3 replacement method for class 'taxa_taxon' tax_cite(x) <- value ## S3 replacement method for class 'taxa_taxon_authority' tax_cite(x) <- value ## S3 method for class 'taxa_taxon_authority' tax_cite(x) ## S3 method for class 'taxa_taxonomy' tax_cite(x) ## S3 replacement method for class 'taxa_taxonomy' tax_cite(x) <- value
## S3 method for class 'taxa_classification' tax_cite(x) ## S3 replacement method for class 'taxa_classification' tax_cite(x) <- value tax_cite(x) tax_cite(x) <- value ## S3 method for class 'taxa_taxon' tax_cite(x) ## S3 replacement method for class 'taxa_taxon' tax_cite(x) <- value ## S3 replacement method for class 'taxa_taxon_authority' tax_cite(x) <- value ## S3 method for class 'taxa_taxon_authority' tax_cite(x) ## S3 method for class 'taxa_taxonomy' tax_cite(x) ## S3 replacement method for class 'taxa_taxonomy' tax_cite(x) <- value
x |
An object with taxon authority dates. |
value |
The taxon citations to set. Inputs will be coerced into a taxon_authority vector. |
x <- taxon_authority(c('Cham. & Schldl.', 'L.'), date = c('1827', '1753'), citation = c(NA, 'Species Plantarum')) tax_cite(x) tax_cite(x)[1] <- "Cham. et al 1984"
x <- taxon_authority(c('Cham. & Schldl.', 'L.'), date = c('1827', '1753'), citation = c(NA, 'Species Plantarum')) tax_cite(x) tax_cite(x)[1] <- "Cham. et al 1984"
Set and get the taxon authority dates in objects that have them, such as taxon_authority objects.
## S3 method for class 'taxa_classification' tax_date(x) ## S3 replacement method for class 'taxa_classification' tax_date(x) <- value tax_date(x) tax_date(x) <- value ## S3 method for class 'taxa_taxon' tax_date(x) ## S3 replacement method for class 'taxa_taxon' tax_date(x) <- value ## S3 replacement method for class 'taxa_taxon_authority' tax_date(x) <- value ## S3 method for class 'taxa_taxon_authority' tax_date(x) ## S3 method for class 'taxa_taxonomy' tax_date(x) ## S3 replacement method for class 'taxa_taxonomy' tax_date(x) <- value
## S3 method for class 'taxa_classification' tax_date(x) ## S3 replacement method for class 'taxa_classification' tax_date(x) <- value tax_date(x) tax_date(x) <- value ## S3 method for class 'taxa_taxon' tax_date(x) ## S3 replacement method for class 'taxa_taxon' tax_date(x) <- value ## S3 replacement method for class 'taxa_taxon_authority' tax_date(x) <- value ## S3 method for class 'taxa_taxon_authority' tax_date(x) ## S3 method for class 'taxa_taxonomy' tax_date(x) ## S3 replacement method for class 'taxa_taxonomy' tax_date(x) <- value
x |
An object with taxon authority dates. |
value |
The taxon authority dates to set. Inputs will be coerced into a character vector. |
x <- taxon_authority(c('Cham. & Schldl.', 'L.'), date = c('1827', '1753')) tax_date(x) tax_date(x)[1] <- "1984" tax_date(x) <- c(NA, '1800')
x <- taxon_authority(c('Cham. & Schldl.', 'L.'), date = c('1827', '1753')) tax_date(x) tax_date(x)[1] <- "1984" tax_date(x) <- c(NA, '1800')
Set and get the taxon ID databases in objects that have them, such as taxon_id objects.
## S3 method for class 'taxa_classification' tax_db(x) ## S3 replacement method for class 'taxa_classification' tax_db(x) <- value tax_db(x) tax_db(x) <- value ## S3 method for class 'taxa_taxon' tax_db(x) ## S3 replacement method for class 'taxa_taxon' tax_db(x) <- value ## S3 method for class 'taxa_taxon_id' tax_db(x) ## S3 replacement method for class 'taxa_taxon_id' tax_db(x) <- value ## S3 method for class 'taxa_taxonomy' tax_db(x) ## S3 replacement method for class 'taxa_taxonomy' tax_db(x) <- value
## S3 method for class 'taxa_classification' tax_db(x) ## S3 replacement method for class 'taxa_classification' tax_db(x) <- value tax_db(x) tax_db(x) <- value ## S3 method for class 'taxa_taxon' tax_db(x) ## S3 replacement method for class 'taxa_taxon' tax_db(x) <- value ## S3 method for class 'taxa_taxon_id' tax_db(x) ## S3 replacement method for class 'taxa_taxon_id' tax_db(x) <- value ## S3 method for class 'taxa_taxonomy' tax_db(x) ## S3 replacement method for class 'taxa_taxonomy' tax_db(x) <- value
x |
An object with taxon authority dates. |
value |
The taxon citations to set. Inputs will be coerced into a taxon_db vector. |
x <- taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi') tax_db(x) tax_db(x) <- 'nbn' tax_db(x)[2] <- 'itis'
x <- taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi') tax_db(x) tax_db(x) <- 'nbn' tax_db(x)[2] <- 'itis'
Set and get the taxon IDs in objects that have them, such as taxon objects.
## S3 method for class 'taxa_classification' tax_id(x) ## S3 replacement method for class 'taxa_classification' tax_id(x) <- value tax_id(x) tax_id(x) <- value ## S3 method for class 'taxa_taxon' tax_id(x) ## S3 replacement method for class 'taxa_taxon' tax_id(x) <- value ## S3 method for class 'taxa_taxonomy' tax_id(x) ## S3 replacement method for class 'taxa_taxonomy' tax_id(x) <- value
## S3 method for class 'taxa_classification' tax_id(x) ## S3 replacement method for class 'taxa_classification' tax_id(x) <- value tax_id(x) tax_id(x) <- value ## S3 method for class 'taxa_taxon' tax_id(x) ## S3 replacement method for class 'taxa_taxon' tax_id(x) <- value ## S3 method for class 'taxa_taxonomy' tax_id(x) ## S3 replacement method for class 'taxa_taxonomy' tax_id(x) <- value
x |
An object with taxon IDs. |
value |
The taxon IDs to set. Inputs will be coerced into a taxon_id vector. |
x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) tax_id(x) tax_id(x) <- paste0('00', tax_id(x)) tax_id(x)[1] <- '00000'
x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) tax_id(x) tax_id(x) <- paste0('00', tax_id(x)) tax_id(x)[1] <- '00000'
Set and get the taxon names in objects that have them, such as taxon objects. Note that this is not the same as adding vector names with names.
## S3 method for class 'taxa_classification' tax_name(x) ## S3 replacement method for class 'taxa_classification' tax_name(x) <- value tax_name(x) tax_name(x) <- value ## S3 method for class 'taxa_taxon' tax_name(x) ## S3 replacement method for class 'taxa_taxon' tax_name(x) <- value ## S3 method for class 'taxa_taxonomy' tax_name(x) ## S3 replacement method for class 'taxa_taxonomy' tax_name(x) <- value
## S3 method for class 'taxa_classification' tax_name(x) ## S3 replacement method for class 'taxa_classification' tax_name(x) <- value tax_name(x) tax_name(x) <- value ## S3 method for class 'taxa_taxon' tax_name(x) ## S3 replacement method for class 'taxa_taxon' tax_name(x) <- value ## S3 method for class 'taxa_taxonomy' tax_name(x) ## S3 replacement method for class 'taxa_taxonomy' tax_name(x) <- value
x |
An object with taxon names. |
value |
The taxon names to set. Inputs will be coerced into a character vector. |
x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) tax_name(x) tax_name(x) <- tolower(tax_name(x)) tax_name(x)[1] <- 'Billy'
x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) tax_name(x) tax_name(x) <- tolower(tax_name(x)) tax_name(x)[1] <- 'Billy'
Set and get the taxon ranks in objects that have them, such as taxon objects.
## S3 method for class 'taxa_classification' tax_rank(x) ## S3 replacement method for class 'taxa_classification' tax_rank(x) <- value tax_rank(x) tax_rank(x) <- value ## S3 method for class 'taxa_taxon' tax_rank(x) ## S3 replacement method for class 'taxa_taxon' tax_rank(x) <- value ## S3 method for class 'taxa_taxonomy' tax_rank(x) ## S3 replacement method for class 'taxa_taxonomy' tax_rank(x) <- value
## S3 method for class 'taxa_classification' tax_rank(x) ## S3 replacement method for class 'taxa_classification' tax_rank(x) <- value tax_rank(x) tax_rank(x) <- value ## S3 method for class 'taxa_taxon' tax_rank(x) ## S3 replacement method for class 'taxa_taxon' tax_rank(x) <- value ## S3 method for class 'taxa_taxonomy' tax_rank(x) ## S3 replacement method for class 'taxa_taxonomy' tax_rank(x) <- value
x |
An object with taxon ranks. |
value |
The taxon ranks to set. Inputs will be coerced into a taxon_rank vector. |
x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) tax_rank(x) tax_rank(x) <- 'species' tax_rank(x)[1] <- taxon_rank('family')
x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) tax_rank(x) tax_rank(x) <- 'species' tax_rank(x)[1] <- taxon_rank('family')
Used to store information about taxa, such as names, ranks, and IDs.
taxon(name = character(0), rank = NA, id = NA, auth = NA, .names = NA, ...)
taxon(name = character(0), rank = NA, id = NA, auth = NA, .names = NA, ...)
name |
The names of taxa. Inputs with be coerced into a character vector if anything else is given. |
rank |
The ranks of taxa. Inputs with be coerced into a taxon_rank vector if anything else is given. |
id |
The ids of taxa. These should be unique identifier and are usually associated with a database. Inputs with be coerced into a taxon_id vector if anything else is given. |
auth |
The authority of the taxon. Inputs with be coerced into a taxon_authority vector if anything else is given. |
.names |
The names of the vector. |
... |
Additional arguments. |
An S3
object of class taxa_taxon
Other classes:
[.taxa_classification()
,
classification()
,
taxon_authority()
,
taxon_db()
,
taxon_id()
,
taxon_rank()
# Create taxon name vector x <- taxon(c('A', 'B', 'C')) x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) names(x) <- c('a', 'b', 'c', 'd') # Get parts of the taxon name vector tax_name(x) tax_rank(x) tax_id(x) tax_db(x) tax_auth(x) tax_author(x) tax_date(x) tax_cite(x) # Set parts of the taxon name vector tax_name(x) <- tolower(tax_name(x)) tax_rank(x)[1] <- NA tax_name(x)['b'] <- 'Billy' tax_id(x) <- '9999' tax_db(x) <- 'itis' tax_auth(x) <- NA tax_author(x)[2:3] <- c('Joe', 'Billy') tax_date(x) <- c('1999', '2013', '1796', '1899') tax_cite(x)[1] <- 'Linnaeus, C. (1771). Mantissa plantarum altera generum.' # Manipulate taxon name vectors x[1:3] x[tax_rank(x) > 'family'] x['b'] <- NA x[c('c', 'd')] <- 'unknown' is.na(x) # Use 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)
# Create taxon name vector x <- taxon(c('A', 'B', 'C')) x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'), rank = c('species', 'genus', 'phylum', 'family'), id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'), auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789')) names(x) <- c('a', 'b', 'c', 'd') # Get parts of the taxon name vector tax_name(x) tax_rank(x) tax_id(x) tax_db(x) tax_auth(x) tax_author(x) tax_date(x) tax_cite(x) # Set parts of the taxon name vector tax_name(x) <- tolower(tax_name(x)) tax_rank(x)[1] <- NA tax_name(x)['b'] <- 'Billy' tax_id(x) <- '9999' tax_db(x) <- 'itis' tax_auth(x) <- NA tax_author(x)[2:3] <- c('Joe', 'Billy') tax_date(x) <- c('1999', '2013', '1796', '1899') tax_cite(x)[1] <- 'Linnaeus, C. (1771). Mantissa plantarum altera generum.' # Manipulate taxon name vectors x[1:3] x[tax_rank(x) > 'family'] x['b'] <- NA x[c('c', 'd')] <- 'unknown' is.na(x) # Use 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)
Used to store information on taxon authorities, such as author names, date, and citation.
taxon_authority( author = character(), date = "", citation = "", .names = "", extract_date = TRUE )
taxon_authority( author = character(), date = "", citation = "", .names = "", extract_date = TRUE )
author |
Zero or more author names. |
date |
Zero or more dates. |
citation |
Zero or more literature citations. |
.names |
The names of the vector. |
extract_date |
If |
An S3
object of class taxa_taxon_authority
Other classes:
[.taxa_classification()
,
classification()
,
taxon()
,
taxon_db()
,
taxon_id()
,
taxon_rank()
# Making new objects x <- taxon_authority(c('A', 'B', 'C')) x <- taxon_authority(c('Cham. & Schldl.', 'L.'), date = c('1827', '1753')) # Manipulating objects as.character(x) x[2] x[2] <- 'ABC' names(x) <- c('a', 'b') x['b'] <- 'David Bowie' tax_author(x)[1] <- tolower(tax_author(x)[1]) tax_author(x) tax_date(x) <- c('2000', '1234') tax_date(x) tax_cite(x)[2] <- c('Linnaeus, C. (1771). Mantissa plantarum altera generum.') tax_cite(x) # Using as columns in tables tibble::tibble(x = x, y = 1:2) data.frame(x = x, y = 1:2) # Converting to tables tibble::as_tibble(x) as_data_frame(x)
# Making new objects x <- taxon_authority(c('A', 'B', 'C')) x <- taxon_authority(c('Cham. & Schldl.', 'L.'), date = c('1827', '1753')) # Manipulating objects as.character(x) x[2] x[2] <- 'ABC' names(x) <- c('a', 'b') x['b'] <- 'David Bowie' tax_author(x)[1] <- tolower(tax_author(x)[1]) tax_author(x) tax_date(x) <- c('2000', '1234') tax_date(x) tax_cite(x)[2] <- c('Linnaeus, C. (1771). Mantissa plantarum altera generum.') tax_cite(x) # Using as columns in tables tibble::tibble(x = x, y = 1:2) data.frame(x = x, y = 1:2) # Converting to tables tibble::as_tibble(x) as_data_frame(x)
Used to store the names of taxon databases defined in db_ref. Primarily used in other classes like taxon_id to define databases for each item.
taxon_db(db = character(), .names = NULL, ...)
taxon_db(db = character(), .names = NULL, ...)
db |
Zero or more taxonomic database names. Should be a name contained in db_ref. Inputs will be transformed to a character vector if possible. |
.names |
The names of the vector. |
... |
Additional arguments. |
An S3
object of class taxa_taxon_db
Other classes:
[.taxa_classification()
,
classification()
,
taxon()
,
taxon_authority()
,
taxon_id()
,
taxon_rank()
# Making new objects x <- taxon_db(c('ncbi', 'ncbi', 'itis')) x # Manipulating objects as.character(x) x[2:3] x[2:3] <- 'nbn' names(x) <- c('a', 'b', 'c') x['b'] x['b'] <- 'nbn' x[x == 'itis'] <- 'gbif' # Using as columns in tables tibble::tibble(x = x, y = 1:3) data.frame(x = x, y = 1:3) # Converting to tables tibble::as_tibble(x) as_data_frame(x) # Trying to use an invalid database generates an error # x <- taxon_db(c('ncbi', 'ncbi', 'my_custom_db')) # x[x == 'itis'] <- 'my_custom_db' # Listing known databases and their properties db_ref$get() # Adding and using a new database db_ref$set(name = 'my_custom_db', desc = 'I just made this up') db_ref$get() x <- taxon_db(c('ncbi', 'ncbi', 'my_custom_db'))
# Making new objects x <- taxon_db(c('ncbi', 'ncbi', 'itis')) x # Manipulating objects as.character(x) x[2:3] x[2:3] <- 'nbn' names(x) <- c('a', 'b', 'c') x['b'] x['b'] <- 'nbn' x[x == 'itis'] <- 'gbif' # Using as columns in tables tibble::tibble(x = x, y = 1:3) data.frame(x = x, y = 1:3) # Converting to tables tibble::as_tibble(x) as_data_frame(x) # Trying to use an invalid database generates an error # x <- taxon_db(c('ncbi', 'ncbi', 'my_custom_db')) # x[x == 'itis'] <- 'my_custom_db' # Listing known databases and their properties db_ref$get() # Adding and using a new database db_ref$set(name = 'my_custom_db', desc = 'I just made this up') db_ref$get() x <- taxon_db(c('ncbi', 'ncbi', 'my_custom_db'))
Used to store the ID corresponding to taxa, either arbitrary or from a particular taxonomy database. This is typically used to store taxon IDs in taxon objects.
taxon_id(id = character(), db = "", .names = NULL)
taxon_id(id = character(), db = "", .names = NULL)
id |
Zero or more taxonomic ids. Inputs will be transformed to a character vector if possible. |
db |
The name(s) of the database(s) associated with the IDs. If not |
.names |
The names that will be applied to the vector. |
An S3
object of class taxa_taxon_id
Other classes:
[.taxa_classification()
,
classification()
,
taxon()
,
taxon_authority()
,
taxon_db()
,
taxon_rank()
# Making new objects x <- taxon_id(c('A', 'B', 'C')) x <- taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi') x <- taxon_id(c('9606', '1386', '4890', '4345'), db = c('ncbi', 'ncbi', 'itis', 'itis')) names(x) <- c('a', 'b', 'c', 'd') # Manipulating objects as.character(x) x[2:3] x[2:3] <- 'ABC' x[c('a', 'c')] <- '123' x[['b']] <- taxon_id('123423', db = 'ncbi') tax_db(x) tax_db(x) <- 'nbn' c(x, x) # Using as columns in tables tibble::tibble(x = x, y = 1:4) data.frame(x = x, y = 1:4) # Convert to tables tibble::as_tibble(x) as_data_frame(x) # Trying to use an invalid ID with a specified database causes an error #taxon_id('NOLETTERS', db = 'ncbi')
# Making new objects x <- taxon_id(c('A', 'B', 'C')) x <- taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi') x <- taxon_id(c('9606', '1386', '4890', '4345'), db = c('ncbi', 'ncbi', 'itis', 'itis')) names(x) <- c('a', 'b', 'c', 'd') # Manipulating objects as.character(x) x[2:3] x[2:3] <- 'ABC' x[c('a', 'c')] <- '123' x[['b']] <- taxon_id('123423', db = 'ncbi') tax_db(x) tax_db(x) <- 'nbn' c(x, x) # Using as columns in tables tibble::tibble(x = x, y = 1:4) data.frame(x = x, y = 1:4) # Convert to tables tibble::as_tibble(x) as_data_frame(x) # Trying to use an invalid ID with a specified database causes an error #taxon_id('NOLETTERS', db = 'ncbi')
Used to store taxon ranks, possibly associated with a taxonomy database. This is typically used to store taxon ranks in taxon objects.
taxon_rank( rank = character(), .names = NULL, levels = NULL, guess_order = TRUE )
taxon_rank( rank = character(), .names = NULL, levels = NULL, guess_order = TRUE )
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
|
guess_order |
If |
An S3
object of class taxa_taxon_rank
Other classes:
[.taxa_classification()
,
classification()
,
taxon()
,
taxon_authority()
,
taxon_db()
,
taxon_id()
# 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')
# 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')