read_sql {basedosdados}R Documentation

Query out datalake and get results in a tibble

Description

Query out datalake and get results in a tibble

Usage

read_sql(query, billing_project_id = get_billing_id(), page_size = 1000)

Arguments

query

a string containing a valid SQL query.

billing_project_id

a string containing your billing project id. If you've run set_billing_id then feel free to leave this empty.

page_size

bigrquery internal, how many rows per page should there be.

Value

A tibble containing the query's output.

Examples


## Not run: 

set_billing_id("<your id here>")

query <- "SELECT
pib.id_municipio,
pop.ano,
pib.PIB / pop.populacao * 1000 as pib_per_capita
FROM `basedosdados.br_ibge_pib.municipios` as pib
JOIN `basedosdados.br_ibge_populacao.municipios` as pop
ON pib.id_municipio = pop.id_municipio
LIMIT 5 "

data <- read_sql(query)

# in case you want to write your data on disk as a .xlsx, .csv or .Rds file.

library(writexl)
library(readr)

dir <- tempdir()

write_xlsx(data, file.path(dir, "data.xlsx"))
write_csv(data, file.path(dir, "data.csv"))
saveRDS(data, file.path(dir, "data.Rds"))


## End(Not run)


[Package basedosdados version 0.0.5 Index]