rOpenSci Traits Package
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
$ RInstall the stable version of the package from CRAN:
install.packages("traits")Or development version from GitHub:
devtools::install_github("ropensci/traits")Load traits
library("traits")Example 1: Query trait data for Willow
Get trait data for Willow (Salix spp.)
(salix <- betydb_search("Salix Vcmax"))
#> Source: local data frame [14 x 31]
#>
#> access_level author checked citation_id citation_year city
#> (int) (chr) (int) (int) (int) (chr)
#> 1 4 Merilo 1 430 2005 Saare
#> 2 4 Merilo 1 430 2005 Saare
#> 3 4 Merilo 1 430 2005 Saare
#> 4 4 Merilo 1 430 2005 Saare
#> 5 4 Wullschleger 1 51 1993 NA
#> 6 4 Merilo 1 430 2005 Saare
#> 7 4 Merilo 1 430 2005 Saare
#> 8 4 Merilo 1 430 2005 Saare
#> 9 4 Merilo 1 430 2005 Saare
#> 10 4 Merilo 1 430 2005 Saare
#> 11 4 Merilo 1 430 2005 Saare
#> 12 4 Merilo 1 430 2005 Saare
#> 13 4 Merilo 1 430 2005 Saare
#> 14 4 Wang 1 381 2010 NA
#> Variables not shown: commonname (chr), cultivar_id (int), date (chr),
#> dateloc (chr), genus (chr), id (int), lat (dbl), lon (dbl), mean (chr),
#> month (dbl), n (int), notes (chr), result_type (chr), scientificname
#> (chr), site_id (int), sitename (chr), species_id (int), stat (chr),
#> statname (chr), trait (chr), trait_description (chr), treatment (chr),
#> treatment_id (int), units (chr), year (dbl)
# equivalent:
# (out <- betydb_search("willow"))Summarise data from the output data.frame
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)
Summarise data from the output data.frame
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.
All code used in the manuscript is available on GitHub at https://github.com/ebimodeling/betydb_manuscript/.
Step 1: Query Yield data for switchgrass and miscanthus:
Query and agronomic metadata
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.
Now compute specific managements of interest
Subset species of interest; combine with agronomic data
Reproduce figure 4a, but without regression fits for simplicity
Advanced Queries
The tables above will return values of _tablename_id that can be used to query other tables
Query a Single trait record by its id
Query a single Species
Query a single Citation
Query a single Site
Last updated