traitecoevo/austraits

Function/tutorial for extracting a particularly family or genus or trait

Closed this issue · 2 comments

Is your feature request related to a problem? Please describe.
@pieterarnold reached out and wanted to subset austraits to a particular family and trait (Proteaceae and SLA), I wrote

Describe the solution you'd like
A function like extract_trait/extract_dataset but perhaps more generalised to allow for different levels of taxon.

Describe alternatives you've considered
A vignette perhaps for doing this before we make major changes

# You'll see in austraits$taxa is where you'll find all the taxonomic info
austraits$taxa

# Will give you families
austraits$taxa$family

# Lets find all the Proteaceae
str_which(austraits$taxa$family, "Proteaceae") #Gives you all the indices for Proteaceae
str_which(austraits$taxa$family, "Proteaceae") %>% length() #1604 species

# Find the cooresponding taxon name for those that belong in Proteaceae
austraits$taxa %>% slice( str_which(austraits$taxa$family, "Proteaceae") ) # This code is equivilant to austraits$taxa[str_which(austraits$taxa$family, "Proteaceae"),]

austraits$taxa %>% slice( str_which(austraits$taxa$family, "Proteaceae") ) %>% nrow() #Matches to 1604- what we expected!

# Pull the taxon names from this taxa table
proteaceae_sp <- austraits$taxa %>% slice( str_which(austraits$taxa$family, "Proteaceae") ) %>% pull(taxon_name) #This code is equivalent to using $ to select a column

# Extract data for Proteaceae
proteaceae_sla <- austraits %>% extract_trait("specific_leaf_area", taxon_names = proteaceae_sp)

# Just some checking
proteaceae_sla$traits$trait_name %>% unique() #Only SLA

proteaceae_sla$taxa$family %>% unique() #Only Proteaceae

Nice @fontikar!

I haven't merged into master yet! Currently on 'upgrade' branch - 0f92323
Will close when we release the new upgrades