download {basedosdados}R Documentation

Write the results of a query locally to a comma-separated file.

Description

Write the results of a query locally to a comma-separated file.

Usage

download(query, path, billing_project_id = get_billing_id(), page_size = 1000)

Arguments

query

a string containing a valid SQL query.

path

String with the output file's name. If running an R Project relative location can be provided. Passed to readr::write_csv's file argument.

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.

Details

Currently there's only support for UTF-8 encoding. Users requiring more control over writing should use read_sql to get the data in memory and custom code from there.

Value

Invisibly returns the query's output in a tibble. Intended to be used for side-effects. If you simply want to load a query's result in memory, use read_sql.

Examples


## Not run: 

dir <- tempdir()

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 <- download(query, file.path(dir, "pib_per_capita.csv"))

## End(Not run)



[Package basedosdados version 0.0.5 Index]