taxize - pass many names to tax_name() and save to file

A user asked essentially:

How can I pass many names to tax_name() and save results to a file

tax_name() accepts a vector or list of names. In addition, it:

  • accepts one or more ranks if you want to get more than one rank back, and
  • allows you to get data back from NCBI, ITIS, or both data sources

tax_name() returns a data.frame, ready for easy downstream manipulation, combination with other data, or writing to a file.

Here’s an example of passing three names to tax_name(), and saving that result to a file.

library(taxize)
mynames <- c("Acanthamoeba", "Pinus contorta", "Ursus")
res <- tax_name(query = mynames, get = "superkingdom", db = 'ncbi')
res
#>     db          query superkingdom
#> 1 ncbi   Acanthamoeba    Eukaryota
#> 2 ncbi Pinus contorta    Eukaryota
#> 3 ncbi          Ursus    Eukaryota

Write to a file with write.csv. Alternatively, use readr package for easier usage.

write.csv(res, file = "myfile.csv", row.names = FALSE)

Then, read that file back in.

read.csv("myfile.csv", stringsAsFactors = FALSE)
#>     db          query superkingdom
#> 1 ncbi   Acanthamoeba    Eukaryota
#> 2 ncbi Pinus contorta    Eukaryota
#> 3 ncbi          Ursus    Eukaryota