bd_write | R Documentation |
bdplyr()
to diskWrites a remote table to disk that was called via bdplyr.
It will collect the data and write to disk in the chosen format.
You will only need this function if you have not yet collected the data
using the bd_collect()
.
The comprehensive function bd_write()
takes as a parameter .write_fn
,
which will be the name of some function (without parentheses) capable of
writing a tibble to disk.
As helpers, the bd_write_rds()
and bd_write_csv()
functions make it
easier to write in these formats, more common in everyday life, calling
writing functions from {readr}
package.
bd_write( .lazy_tbl, .write_fn = `?`(typed::Function()), path = `?`(typed::Character(length = 1)), overwrite = `?`(FALSE, typed::Logical(1)), ... ) bd_write_rds(.lazy_tbl, path, overwrite = FALSE, compress = "none", ...) bd_write_csv( .lazy_tbl, path = `?`(typed::Character(1)), overwrite = `?`(FALSE, typed::Logical(1)), ... )
.lazy_tbl |
A lazy tibble, tipically the output of |
.write_fn |
A function for writing the result of a tibble to disk. Do not use () afther the function's name, the function object should be passed. Some functions the user might consider are: writexl::write_xlsx, jsonlite::write_json, foreign::write.dta, arrow::write_feather, etc. |
path |
String containing the path for the file to be created. The desired folders must already exist and the file should normally end with the corresponding extension. |
overwrite |
FALSE by default. Indicates whether the local file should be overwritten if it already exists. Use with care. |
... |
Parameters passed to the |
compress |
For |
String containing the path to the created file.
## Not run: cool_db <- basedosdados:: # setup billing basedosdados::set_billing_id("MY-BILLING-ID") # connect with a Base dos Dados db cool_db_ssp <- basedosdados::bdplyr( "basedosdados.br_sp_gov_ssp.ocorrencias_registradas") # subset the data my_subset <- cool_db_ssp %>% dplyr::filter(ano == 2021, mes == 04) # write it in csv - generic function basedosdados::bd_write(.lazy_tbl = my_subset, .write_fn = write.csv, "data-raw/ssp_subset.csv" ) # write in .xlsx basedosdados::bd_write(.lazy_tbl = my_subset, .write_fn = writexl::write_xlsx, "data-raw/ssp_subset.xlsx" ) # using the derivatives functions # to csv basedosdados::bd_write_csv(.lazy_tbl = my_subset, "data-raw/ssp_subset2.csv" ) #' # to rds basedosdados::bd_write_rds(.lazy_tbl = my_subset, "data-raw/ssp_subset.rds" ) # to rds - with compression basedosdados::bd_write_rds(.lazy_tbl = my_subset, "data-raw/ssp_subset2.rds", compress = "gz" ) # to rds - with HARD compression basedosdados::bd_write_rds(.lazy_tbl = my_subset, "data-raw/ssp_subset3.rds", compress = "xz" ) ## using other write functions # json basedosdados::bd_write(.lazy_tbl = my_subset, .write_fn = jsonlite::write_json, "data-raw/ssp_subset.json" ) # dta basedosdados::bd_write(.lazy_tbl = my_subset, .write_fn = foreign::write.dta, "data-raw/ssp_subset.dta") ) # feather basedosdados::bd_write(.lazy_tbl = my_subset, .write_fn = arrow::write_feather, "data-raw/ssp_subset.feather" ) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.