get_hierarchy: Recursively Retrieve Parent Taxonomic Hierarchy

View source: R/dyntaxa_api_functions.R

get_hierarchyR Documentation

Recursively Retrieve Parent Taxonomic Hierarchy

Description

This helper function retrieves the taxonomic hierarchy for a given taxon ID by recursively traversing its parent relationships in the provided dataset.

Usage

get_hierarchy(taxon_id, data)

Arguments

taxon_id

A character string representing the taxon ID for which the hierarchy is to be retrieved.

data

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

Value

A character vector containing the hierarchy of parent scientificName values, starting with the immediate parent and ascending.

Examples

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

# Get hierarchy for taxon ID "3"
SHARK4R:::get_hierarchy("3", data)
# [1] "Phylum" "Kingdom"


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