read_sql {basedosdados} | R Documentation |
Query our datalake and get results in a tibble
Description
read_sql
is given either a fully-written SQL query through the query
argument or a valid table name through the table
argument.
Usage
read_sql(query, billing_project_id = get_billing_id())
Arguments
query |
a string containing a valid SQL query. |
billing_project_id |
a string containing your billing project id. If you've run |
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.municipio` as pib
JOIN `basedosdados.br_ibge_populacao.municipio` 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.2.2 Index]