The rOpenSci traits package is an R client for various sources of species trait data. The traits package provides functions that interface with the BETYdb API.
These instructions are from the traits package documentation, which is released with a MIT-BSD license.
Installation
Launch R
$R
Install the stable version of the package from CRAN:
library("dplyr")salix %>%group_by(scientificname, trait)%>%mutate(.mean =as.numeric(mean)) %>%summarise(mean =round(mean(.mean, na.rm =TRUE), 2), min =round(min(.mean, na.rm =TRUE), 2), max =round(max(.mean, na.rm =TRUE), 2), n =length(n))#> Source: local data frame [4 x 6]#> Groups: scientificname [?]#> #> scientificname trait mean min max n#> (chr) (chr) (dbl) (dbl) (dbl) (int)#> 1 Salix Vcmax 65.00 65.00 65.00 1#> 2 Salix dasyclados Vcmax 46.08 34.30 56.68 4#> 3 Salix sachalinensis × miyabeana Vcmax 79.28 79.28 79.28 1#> 4 Salix viminalis Vcmax 43.04 19.99 61.29 8
BETYdb is the Biofuel Ecophysiological Traits and Yields Database. You can get many different types of data from this database, including trait data.
Function setup: All functions are prefixed with betydb_. Plural function names like betydb_traits() accept parameters and always give back a data.frame, while singular function names like betydb_trait() accept an ID and give back a list.
The idea with the functions with plural names is to search for either traits, species, etc., and with the singular function names to get data by one or more IDs.
Example 2: Get yield data for Switchgrass (Panicum virgatum)
Example 3: Link Managements to Switchgrass and Miscanthus Yields
Note: this code illustrates how to join management events to yield records. It replicates figure 4a from LeBauer et al 2018. Could similarly be done with traits.
Note: treatments are categorical, each study has >=1 treatment; managements describe the actual activities (planting, fertilization, irrigation, etc) and sometimes the level (planting density, fertilization rate, etc).
There is a many-to-many relationship between treatments and managements. One treatment can have many managements (e.g. control treatment had a planting date, a level of fertilization, etc). And each management can be associated with one or more treatments - e.g. the same planting for both a control and fertilized treatment.
So first we query the tables, then join them, then create new columns for the date and level of specific managements.
treatments <-betydb_query(table ='treatments', limit ='none')%>% dplyr::mutate(treatment_id = id)%>% dplyr::select(treatment_id, name, definition, control)managements <-betydb_query(table ='managements', limit ='none')%>% dplyr::filter(mgmttype %in%c('fertilizer_N', 'fertilizer_N_rate', 'planting', 'irrigation')) %>% dplyr::mutate(management_id = id)%>% dplyr::select(management_id, date, mgmttype, level, units)# now link managements to treatmentsm <-betydb_query(table ='managements', associations_mode ='ids', limit ='none')managements_treatments <- m %>%select(treatment_id = `associated treatment ids`, management_id = id)%>% tidyr::unnest()managements <- managements %>%left_join(managements_treatments, by ='management_id')%>%left_join(treatments, by ='treatment_id')