add_hierarchy_column: Add Taxonomic Hierarchy Column to a Dataset

View source: R/dyntaxa_api_functions.R

add_hierarchy_columnR Documentation

Add Taxonomic Hierarchy Column to a Dataset

Description

This function adds a new column, hierarchy, to a dataset, where each row contains the taxonomic hierarchy of parent scientificName values for the given taxonId. The hierarchy is constructed using a recursive helper function.

Usage

add_hierarchy_column(data, data_dwca = NULL, verbose = TRUE)

Arguments

data

A data frame containing taxonomic information. Must include columns taxonId, parentNameUsageID, and scientificName.

data_dwca

A data frame representing the complete taxonomic dataset (e.g., full taxonomy table). Must include the same columns as data. Defaults to data if not provided.

verbose

Logical. If TRUE, the function will print additional messages to provide feedback on its progress. Default is TRUE.

Value

A data frame with an additional hierarchy column. The hierarchy column contains a string representing the lineage of parent scientificName values, separated by " > ".

Examples

# Example dataset
data <- tibble::tibble(
  taxonId = c("1", "2", "3"),
  parentNameUsageID = c(NA, "1", "2"),
  scientificName = c("Kingdom", "Phylum", "Class")
)

# Add hierarchy column
data_with_hierarchy <- SHARK4R:::add_hierarchy_column(data)
print(data_with_hierarchy)


sharksmhi/SHARK4R documentation built on Jan. 9, 2025, 5:15 p.m.