traitecoevo / austraits

R package for accessing the AusTraits Plant database
https://traitecoevo.github.io/austraits/
MIT License
19 stars 1 forks source link

Create `extract_` function that works for any column with the traits table #82

Open ehwenk opened 12 months ago

ehwenk commented 12 months ago

Context The extract and join functions act on the entire database, while any additional filtering of columns that a user might wish to perform need to be done on just the traits table. This means you need to first extract and join any information you want, then save the output as a tmp object, then start a new pip that performs additional filtering on tmp$traits. It would be nice if you could instead have a single pipe that extracts a particular collection of traits, taxa, and then also filters on other specified columns (i.e. life_stage, basis_of_record).

Describe the solution you'd like As an example:

my_data <- austraits %>%
  extract_trait("leaf_mass_per_area") %>%
  extract_taxa(genus = "Eucalyptus") %>%
  extract_column(column = "life_stage", value = "adult") %>%
  extract_column(column = "basis_of_record", value = "field") %>%
  join_locations() 

This would allow all manipulations to be linked in a single pipe -- and mean that if you join_contexts at the end, you'll only join the context properties that pertain to the filtered data.

Right now you have to use the join functions before you do any filtering just on the traits table (using filter).

ehwenk commented 4 weeks ago

It has been discussed to expand extract_ to allow extractions based on any field in any of the relational tables.

fontikar commented 4 weeks ago

Generalising extract_ found here