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
1
$ R
Copied!
Install the stable version of the package from CRAN:
1
install.packages("traits")
Copied!
Or development version from GitHub:
1
devtools::install_github("ropensci/traits")
Copied!

Load traits

1
library("traits")
Copied!

Example 1: Query trait data for Willow

Get trait data for Willow (Salix spp.)
1
(salix <- betydb_search("Salix Vcmax"))
2
#> Source: local data frame [14 x 31]
3
#>
4
#> access_level author checked citation_id citation_year city
5
#> (int) (chr) (int) (int) (int) (chr)
6
#> 1 4 Merilo 1 430 2005 Saare
7
#> 2 4 Merilo 1 430 2005 Saare
8
#> 3 4 Merilo 1 430 2005 Saare
9
#> 4 4 Merilo 1 430 2005 Saare
10
#> 5 4 Wullschleger 1 51 1993 NA
11
#> 6 4 Merilo 1 430 2005 Saare
12
#> 7 4 Merilo 1 430 2005 Saare
13
#> 8 4 Merilo 1 430 2005 Saare
14
#> 9 4 Merilo 1 430 2005 Saare
15
#> 10 4 Merilo 1 430 2005 Saare
16
#> 11 4 Merilo 1 430 2005 Saare
17
#> 12 4 Merilo 1 430 2005 Saare
18
#> 13 4 Merilo 1 430 2005 Saare
19
#> 14 4 Wang 1 381 2010 NA
20
#> Variables not shown: commonname (chr), cultivar_id (int), date (chr),
21
#> dateloc (chr), genus (chr), id (int), lat (dbl), lon (dbl), mean (chr),
22
#> month (dbl), n (int), notes (chr), result_type (chr), scientificname
23
#> (chr), site_id (int), sitename (chr), species_id (int), stat (chr),
24
#> statname (chr), trait (chr), trait_description (chr), treatment (chr),
25
#> treatment_id (int), units (chr), year (dbl)
26
# equivalent:
27
# (out <- betydb_search("willow"))
Copied!
Summarise data from the output data.frame
1
library("dplyr")
2
salix %>%
3
group_by(scientificname, trait) %>%
4
mutate(.mean = as.numeric(mean)) %>%
5
summarise(mean = round(mean(.mean, na.rm = TRUE), 2),
6
min = round(min(.mean, na.rm = TRUE), 2),
7
max = round(max(.mean, na.rm = TRUE), 2),
8
n = length(n))
9
#> Source: local data frame [4 x 6]
10
#> Groups: scientificname [?]
11
#>
12
#> scientificname trait mean min max n
13
#> (chr) (chr) (dbl) (dbl) (dbl) (int)
14
#> 1 Salix Vcmax 65.00 65.00 65.00 1
15
#> 2 Salix dasyclados Vcmax 46.08 34.30 56.68 4
16
#> 3 Salix sachalinensis × miyabeana Vcmax 79.28 79.28 79.28 1
17
#> 4 Salix viminalis Vcmax 43.04 19.99 61.29 8
Copied!
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)

1
out <- betydb_search(query = "Switchgrass Yield")
Copied!
Summarise data from the output data.frame
1
library("dplyr")
2
out %>%
3
group_by(id) %>%
4
summarise(mean_result = mean(as.numeric(mean), na.rm = TRUE)) %>%
5
arrange(desc(mean_result))
Copied!
1
## Source: local data frame [509 x 2]
2
##
3
## id mean_result
4
## 1 1666 27.36
5
## 2 16845 27.00
6
## 3 1669 26.36
7
## 4 16518 26.00
8
## 5 1663 25.35
9
## 6 16742 25.00
10
## 7 1594 24.78
11
## 8 1674 22.71
12
## 9 1606 22.54
13
## 10 1665 22.46
14
## .. ... ...
Copied!

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

1
betydb_trait(id = 10)
Copied!
1
## $created_at
2
## NULL
3
##
4
## $description
5
## [1] "Leaf Percent Nitrogen"
6
##
7
## $id
8
## [1] 10
9
##
10
## $label
11
## NULL
12
##
13
## $max
14
## [1] "10"
15
##
16
## $min
17
## [1] "0.02"
18
##
19
## $name
20
## [1] "leafN"
21
##
22
## $notes
23
## [1] ""
24
##
25
## $standard_name
26
## NULL
27
##
28
## $standard_units
29
## NULL
30
##
31
## $units
32
## [1] "percent"
33
##
34
## $updated_at
35
## [1] "2011-06-06T09:40:42-05:00"
Copied!

Query a single Species

1
betydb_specie(id = 10)
Copied!
1
## $AcceptedSymbol
2
## [1] "ACKA2"
3
##
4
## $commonname
5
## [1] "karroothorn"
6
##
7
## $created_at
8
## NULL
9
##
10
## $genus
11
## [1] "Acacia"
12
##
13
## $id
14
## [1] 10
15
##
16
## $notes
17
## [1] ""
18
##
19
## $scientificname
20
## [1] "Acacia karroo"
21
##
22
## $spcd
23
## NULL
24
##
25
## $species
26
## [1] "karroo"
27
##
28
## $updated_at
29
## [1] "2011-03-01T15:02:25-06:00"
Copied!

Query a single Citation

1
betydb_citation(10)
Copied!
1
## $author
2
## [1] "Casler"
3
##
4
## $created_at
5
## NULL
6
##
7
## $doi
8
## [1] "10.2135/cropsci2003.2226"
9
##
10
## $id
11
## [1] 10
12
##
13
## $journal
14
## [1] "Crop Science"
15
##
16
## $pdf
17
## [1] "http://crop.scijournals.org/cgi/reprint/43/6/2226.pdf"
18
##
19
## $pg
20
## [1] "2226–2233"
21
##
22
## $title
23
## [1] "Cultivar X environment interactions in switchgrass"
24
##
25
## $updated_at
26
## NULL
27
##
28
## $url
29
## [1] "http://crop.scijournals.org/cgi/content/abstract/43/6/2226"
30
##
31
## $user_id
32
## NULL
33
##
34
## $vol
35
## [1] 43
36
##
37
## $year
38
## [1] 2003
Copied!

Query a single Site

1
betydb_site(id = 1)
Copied!
1
## $city
2
## [1] "Aliartos"
3
##
4
## $country
5
## [1] "GR"
6
##
7
## $geometry
8
## [1] "POINT (23.17 38.37 114.0)"
9
##
10
## $greenhouse
11
## [1] FALSE
12
##
13
## $notes
14
## [1] ""
15
##
16
## $sitename
17
## [1] "Aliartos"
18
##
19
## $state
20
## [1] ""
Copied!
Last modified 3yr ago