Last active
October 29, 2019 03:21
-
-
Save DustinAlandzes/850ec130f83a13ef240a4e312a598b12 to your computer and use it in GitHub Desktop.
How to load bigquery data with r, you need to create a gcp project (here, mine is called "public-bigquery") and copy the data over before running this: https://console.cloud.google.com/bigquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "R Notebook" | |
output: html_notebook | |
--- | |
# install bigrquery if needed | |
install.packages("httpuv") | |
install.packages("gargle") | |
install.packages("bigrquery") | |
library(httpuv) | |
library(gargle) | |
library(bigrquery) | |
# load libraries | |
library(bigrquery) | |
library(DBI) | |
# authenticate with google | |
bq_auth(use_oob = gargle::gargle_oob_default()) | |
# connect to epa_historical_air_quality in BigQuery | |
connection <- dbConnect( | |
bigrquery::bigquery(), | |
project = "public-bigquery", | |
dataset = "epa_historical_air_quality", | |
) | |
# list tables | |
dbListTables(connection) | |
# perform a query | |
query = "SELECT * FROM `bigquery-public-data.epa_historical_air_quality.air_quality_annual_summary` LIMIT 1000" | |
df <- dbGetQuery(connection, query, n = 10) | |
write.csv(df, 'test.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yanluu