Learn R Programming

bigrquery (version 0.2.0)

src_bigquery: A bigquery data source.

Description

Use src_bigquery to connect to an existing bigquery dataset, and tbl to connect to tables within that database.

Usage

src_bigquery(project, dataset, billing = project)

Arguments

project
project id or name
dataset
dataset name
billing
billing project, if different to project

Examples

Run this code
library(dplyr)

# To run this example, replace billing with the id of one of your projects
# set up for billing
pd <- src_bigquery("publicdata", "samples", billing = "465736758727")
pd %>% tbl("shakespeare")

# With bigquery data, it's always a good idea to start by selecting
# only the variables you're interested in - this reduces the amount of
# data that needs to be scanned and hence decreases costs
natality <- pd %>%
  tbl("natality") %>%
  select(year:day, state, child_race, weight_pounds)
year_weights <- natality %>%
  group_by(year) %>%
  summarise(weight = mean(weight_pounds), n = n()) %>%
  collect()
plot(year_weights$year, year_weights$weight, type = "b")

Run the code above in your browser using DataLab