<!--
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{BETYdb Tutorial}
%\VignetteEncoding{UTF-8}
-->

```{r echo=FALSE, eval=FALSE}
knitr::opts_chunk$set(
  comment = "#>", 
  warning = FALSE, 
  message = FALSE,
  cache = TRUE
)
```

[BETYdb](https://www.betydb.org/) 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

```{r}
library("traits")
```

## Traits

Get trait data for _Miscanthus giganteus_

```{r}
out <- betydb_search(query = "Switchgrass Yield")
```

Summarise data from the output `data.frame`

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

Single trait

```{r}
betydb_trait(id = 10)
```

## Species

Single species, _Acacia karroothorn_

```{r}
betydb_specie(id = 10)
```

## Citations

Get citatons searching for _Miscanthus_

```{r}
betydb_citation(10)
```

## Sites

Single site

```{r}
betydb_site(id = 1)
```
