I am trying to access the
NCBI database from R, where I pass on a system command within R using
system(..., intern = T) and return the result back into a variable. The command is a query which retrieves the taxonomy, given a
taxID. It looks like the following:
batch <- system(paste0("esearch -db taxonomy -query \"",taxid.as.string, " [taxID]\" | efetch -format xml | xtract -pattern Taxon -block \"*/Taxon\" -unless Rank -equals \"no rank\" -tab \"\t\" -element Rank,ScientificName"), intern = TRUE)
The variable above
taxid.as.string is a one-element vector and looks like:
> taxid.as.string  "7070, 5741, 658858"
The command searches in the NCBI database for the
TaxIDs 7070, 5741, and 658858, to return the taxonomy for each.
My problem is that it does not return the taxonomy in the proper order.
Instead, it returns the result for 5741, 7070, and then 658858
TaxID. I know that I can keep the vector numeric, loop over it and make a single query at a time.
Why is this the case? Is it possible to keep the order of the result, even if some taxonomies are returned faster?
Thanks in advance!