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 = NULL,
  table = NULL,
  path,
  billing_project_id = get_billing_id(),
  .na = " "
)

Arguments

query

a string containing a valid SQL query.

table

defaults to NULL. If a table name is provided then it'll be concatenated with "basedosdados." and the whole table will be returned.

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.

.na

how should missing values be written in the resulting file? Value passed to na argument of readr::write_csv. Defaults to a whitespace.

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: 

path <- file.path(tempdir(), "pib_per_capita.csv")

bare_query <- "SELECT *
FROM basedosdados.br_tse_eleicoes.bens_candidato
WHERE ano = 2020
AND sigla_uf = \'TO\'"

download(query = bare_query, path = path)

# or download the entire table
download(table = "br_tse_eleicoes.bens_candidato", path = path)


## End(Not run)



[Package basedosdados version 0.2.2 Index]