# BETYdb Tutorial

#### Scott Chamberlain

#### 2020-08-25

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 singlur 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.

## Load traits

    library("traits")

## Traits

Get trait data for Miscanthus giganteus

    out <- betydb_search(query = "Switchgrass Yield")

Summarise data from the output `data.frame`

    suppressPackageStartupMessages(library("dplyr"))
    out %>%
      group_by(id) %>%
      summarise(mean_result = mean(as.numeric(mean), na.rm = TRUE)) %>%
      arrange(desc(mean_result))

    #> # A tibble: 449 x 2
    #>       id mean_result
    #>    <int>       <dbl>
    #>  1  1666        27.4
    #>  2 16845        27
    #>  3  1669        26.4
    #>  4 16518        26
    #>  5  1663        25.4
    #>  6 16742        25
    #>  7  1594        24.8
    #>  8  1674        22.7
    #>  9  1606        22.5
    #> 10  1665        22.5
    #> # … with 439 more rows

Single trait

    betydb_trait(id = 10)

    #> # A tibble: 1 x 13
    #>      id description units notes created_at updated_at name  max   min
    #>   <int> <chr>       <chr> <chr> <chr>      <chr>      <chr> <chr> <chr>
    #> 1    10 Leaf Perce… perc… <NA>  <NA>       2011-06-0… leafN 10    0.02
    #> # … with 4 more variables: standard_name <chr>, standard_units <chr>,
    #> #   label <chr>, type <chr>

## Species

Single species, Acacia karroothorn

    betydb_specie(id = 10)

    #> # A tibble: 1 x 10
    #>      id spcd  genus species scientificname commonname notes created_at
    #>   <int> <chr> <chr> <chr>   <chr>          <chr>      <chr> <chr>
    #> 1    10 <NA>  Acac… karroo  Acacia karroo  karrootho… <NA>  <NA>
    #> # … with 2 more variables: updated_at <chr>, acceptedsymbol <chr>

## Citations

Get citatons searching for Miscanthus

    betydb_citation(10)

    #> # A tibble: 1 x 13
    #>      id author  year title journal   vol pg    url   pdf   created_at updated_at
    #>   <int> <chr>  <int> <chr> <chr>   <int> <chr> <chr> <chr> <chr>      <chr>
    #> 1    10 Casler  2003 Cult… Crop S…    43 2226… http… http… <NA>       <NA>
    #> # … with 2 more variables: doi <chr>, user_id <chr>

## Sites

Single site

    betydb_site(id = 1)

    #> # A tibble: 1 x 8
    #>   city    state country notes sitename greenhouse geometry           time_zone
    #>   <chr>   <chr> <chr>   <chr> <chr>    <lgl>      <chr>              <chr>
    #> 1 Aliart… <NA>  GR      <NA>  Aliartos FALSE      POINT (23.17 38.3… Europe/Ath…