Writes tabular data in the given format.
Arguments
- d
(
data.frame()
)
A data.frame (or tibble) with tidy data.- fpfix
(
character(1)
)
File prefix. The file extension is generated automatically via theformat
argument. For a format of db, this is inserted into thenemo_pfix
column.- format
(
character(1)
)
Output format. One of tsv, csv, parquet, rds, or db.- id
(
character(1)
)
ID to use in the firstnemo_id
column for this table.- dbconn
(
DBIConnection(1)
)
Database connection object (seeDBI::dbConnect
). Used only when format is db.- dbtab
(
character(1)
)
Database table name (seeDBI::dbWriteTable
). Used only when format is db.
Examples
d <- tibble::tibble(name = "foo", data = 123)
fpfix <- file.path(tempdir(), "data_test1")
format <- "csv"
id <- "run1"
nemo_write(d = d, fpfix = fpfix, format = format, id = id)
readr::read_csv(glue::glue("{fpfix}.csv.gz"))
#> Rows: 1 Columns: 3
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (2): nemo_id, name
#> dbl (1): data
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 1 × 3
#> nemo_id name data
#> <chr> <chr> <dbl>
#> 1 run1 foo 123
if (FALSE) { # RPostgres::postgresHasDefault()
# for database writing
con <- DBI::dbConnect(RPostgres::Postgres())
tbl_nm <- "awesome_tbl"
nemo_write(d = d, fpfix = basename(fpfix), format = "db", id = "123", dbconn = con, dbtab = tbl_nm)
DBI::dbListTables(con)
DBI::dbReadTable(con, tbl_nm)
DBI::dbDisconnect(con)
}