ropensci / taxa

taxonomic classes for R
https://docs.ropensci.org/taxa
Other
48 stars 12 forks source link

Do something about how `value` can now return nonsensical output #53

Closed zachary-foster closed 7 years ago

zachary-foster commented 7 years ago

Since the changes in #51, value is a much more flexible version of what return_type was. However, it is now really easy for users to do irrational things without a warning. Since its currently implementation just looks up the data given and subsets it by the result of the function it is in. In some cases the result of the function is observation indexes (obs) and other times it is taxon indexes (subtaxa, roots, etc). It is now easy to subset taxa info with obs indexes and visa versa, which does not make sense:

For example:

> ex_taxmap$obs("info", value = "taxon_names")
$`1`
             1              2              3              4 
    "Mammalia"      "Plantae"      "Felidae" "Notoryctidae" 

$`2`
           5            6 
 "Hominidae" "Solanaceae" 

....

and

> ex_taxmap$supertaxa(value = "name")
$`1`
factor(0)
Levels: cat human mole potato tiger tomato

$`2`
factor(0)
Levels: cat human mole potato tiger tomato

$`3`
[1] tiger
Levels: cat human mole potato tiger tomato

$`4`
[1] tiger
Levels: cat human mole potato tiger tomato

$`5`
[1] tiger
Levels: cat human mole potato tiger tomato

...

I think either a warning should be issued or the function should do its best to convert between taxon indexes and obs indexes when possible and error when not.

For example, ex_taxmap$obs("info", value = "taxon_names") could look up the taxon_names associated with the observations indexes, assuming a taxon_id column exists in ex_taxmap$data$info.

Also, ex_taxmap$supertaxa(value = "n_legs") could look for rows in ex_taxmap$data$info assigned to taxa in the output of supertaxa and use the n_legs values there. This would return NA for taxa not in ex_taxmap$data$info and error if there is more than one entry per taxon, which would be common in many situations.