get_all_parents: Get All Parent Taxa for a Set of Taxon IDs

View source: R/dyntaxa_api_functions.R

get_all_parentsR Documentation

Get All Parent Taxa for a Set of Taxon IDs

Description

This helper function iteratively retrieves all parent taxa for a given set of initial taxon IDs, traversing up the taxonomic hierarchy until the root (taxa with no parents) is reached.

Usage

get_all_parents(data, initial_taxon_ids)

Arguments

data

A data frame containing taxonomic information with columns taxonId and parentNameUsageID. The data can be collected using the get_dyntaxa_dwca() function.

initial_taxon_ids

A character vector of initial taxon IDs for which to retrieve all parent taxa. These IDs should correspond to the taxonId column in the dataset.

Value

A tibble containing all parent taxa for the given initial taxon IDs, including their taxonId, parentNameUsageID, and any other columns present in the input data.

Examples

# Example data
data <- tibble::tibble(
  taxonId = c("1", "2", "3", "4"),
  parentNameUsageID = c(NA, "1", "1", "2"),
  scientificName = c("Root", "Child1", "Child2", "Grandchild1")
)

# Find all parents of taxon IDs "3" and "4"
SHARK4R:::get_all_parents(data, initial_taxon_ids = c("3", "4"))


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