R dplyr Package
R dplyr interface
Using dplyr requires having access to a PostgreSQL server running BETYdb or installing your own.
Comprehensive documentation for the dplyr interface to databases is provided in the dplyr vignette
Connect to Database
library(dplyr)
library(data.table)
## connection to database
d <- list(host = 'localhost',
dbname = 'bety',
user = 'bety',
password = 'bety')
bety <- src_postgres(host = d$host, user = d$user, password = d$password, dbname = d$dbname)Query Miscanthus yield data
species <- tbl(bety, 'species') %>%
select(id, scientificname, genus) %>%
filter(genus == "Miscanthus") %>%
mutate(specie_id = id)
yields <-tbl(bety, 'yields') %>%
select(date, mean, site_id, specie_id)
sites <- tbl(bety, 'sites') %>%
select(id, sitename, city, country) %>%
mutate(site_id = id)
mxgdata <- inner_join(species, yields, by = 'specie_id') %>%
left_join(sites, by = 'site_id') %>%
select(-ends_with(".x"), -ends_with(".y")) %>% # drops duplicate rows
collect()Yield data with experimental treatments
Here we query Miscanthus and Switchgrass yield data along with planting, irrigation, and fertilization rates in order to update teh meta-analysis originally performed by Heaton et al (2004).
Last updated