ropensci / taxa

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

Add NSE variables for dataset taxon ids #59

Closed zachary-foster closed 7 years ago

zachary-foster commented 7 years ago

I found a situation were it would be useful for the taxon ids of observations in a table be available to NSE in all_names(). For observation taxon ids of lists and vectors, it is easy to just use names to get taxon ids. For example, in ...

> ex_taxmap
<Taxmap>
  17 taxa: 1. Mammalia, 2. Plantae, 3. Felidae, 4. Notoryctidae ... 14. typhlops, 15. sapiens, 16. lycopersicum, 17. tuberosum
  17 edges: NA->1, NA->2, 1->3, 1->4, 1->5, 2->6, 3->7, 3->8, 4->9, 5->10, 6->11, 7->12, 8->13, 9->14, 10->15, 11->16, 11->17
  3 data sets:
    info:
      # A tibble: 6 x 4
          name n_legs dangerous taxon_id
        <fctr>  <dbl>     <lgl>    <chr>
      1  tiger      4      TRUE       12
      2    cat      4     FALSE       13
      3   mole      4     FALSE       14
      # ... with 3 more rows
    phylopic_ids:  e148eabb-f138-43c6-b1e4-5cda2180485a ... b6400f39-345a-4711-ab4f-92fd4e22cb1a, 63604565-0406-460b-8cb8-1abe954b3f3a
    foods: a list with 6 items
  1 functions:
 reaction

The taxon ids of ex_taxmap$data$foods could be found by NSE with names(foods), but there is no easy way to get the taxon ids of rows in the ex_taxmap$data$info dataset. names(n_legs) would work, but pick an arbitrary column like that is a it hackish.

So, i am thinking about modifying all_names() to include something like info_taxon_ids for each table in data. This will help in implementing a function for making mapping between any two variables with associated taxon ids. That function might held DRYing out the code for the value option and make #55 easier to implement.