Chapter 7 Accessing Trait Data in R

The rOpenSci traits package makes it easier to query the TERRA REF trait database because 1) you can pass the query parameters in an R function, and the package takes care of putting the parameters into a valid URL and 2) because the package returns data in a tabular format that is ready to analyze.

7.1 Using the R traits package to query the database

7.1.1 Setup

Install the traits package

The traits package can be installed through github using the following command:

Load other packages that we will need to get started.

Create a file that contains your API key. If you have signed up for access to the TERRA REF database, your API key will have been sent to you in an email. You will need this personal key and permissions to access the trait data. If you receive empty (NULL) datasets, it is likely that you do not have permissions.

7.1.1.1 R - using the traits package

The R traits package is an API ‘client’. It does two important things: 1. It makes it easier to specify the query parameters without having to construct a URL 2. It returns the results as a data frame, which is easier to use within R

Lets start with the query of information about Sorghum from the species table

7.1.1.2 R - setting options for the traits package

Notice all of the arguments that the betydb_query function requires? We can change this by setting the default connection options thus:

Now the same query can be reduced to: