R: Add taxonomic parent names to a data.frame

bold_identify_parents {bold} | R Documentation

## Add taxonomic parent names to a data.frame

### Description

Add taxonomic parent names to a data.frame

### Usage

    bold_identify_parents(x, wide = FALSE)

### Arguments

`x` | (data.frame/list) list of data.frames - the output from a call to `bold_identify`. or a single data.frame from the output from same. required.
`wide` | (logical) output in long or wide format. See Details. Default: `FALSE`

### Details

This function gets unique set of taxonomic names from the input data.frame, then queries `bold_tax_name` to get the taxonomic ID, passing it to `bold_tax_id` to get the parent names, then attaches those to the input data.

Records in the input data that do not have matches for parent names simply get NA values in the added columns.

### Value

a list of the same length as the input

### wide vs long format

When `wide = FALSE` you get many rows for each record. Essentially, we `cbind` the taxonomic classification onto the one row from the result of `bold_identify`, giving as many rows as there are taxa in the taxonomic classification.

When `wide = TRUE` you get one row for each record - thus the dimensions of the input data stay the same. For this option, we take just the rows for taxonomic ID and name for each taxon in the taxonomic classification, and name the columns by the taxon rank, so you get `phylum` and `phylum_id`, and so on.

### Examples

    ## Not run:
    df <- bold_identify(sequences = sequences$seq2)

    # long format
    out <- bold_identify_parents(df)
    str(out)
    head(out[[1]])

    # wide format
    out <- bold_identify_parents(df, wide = TRUE)
    str(out)
    head(out[[1]])

    ## End(Not run)

[Package bold version 0.5.0 Index]