
Write content to the connector
Source:R/cnt_generics.R
, R/dbi_methods.R
, R/fs_methods.R
, and 1 more
write_cnt.Rd
Generic implementing of how to write content to the different connector objects:
ConnectorDBI: Uses
DBI::dbWriteTable()
to write the table to the DBI connection.
ConnectorFS: Uses
write_file()
to Write a file based on the file extension. The underlying function used, and thereby also the arguments available through...
depends on the file extension.
If no file extension is provided in the name
, the default extension will be
automatically appended (configurable via options(connector.default_ext = "csv")
,
defaults to "csv").
ConnectorLogger: Logs the write operation and calls the underlying connector method.
Usage
write_cnt(
connector_object,
x,
name,
overwrite = zephyr::get_option("overwrite", "connector"),
...
)
# S3 method for class 'ConnectorDBI'
write_cnt(
connector_object,
x,
name,
overwrite = zephyr::get_option("overwrite", "connector"),
...
)
# S3 method for class 'ConnectorFS'
write_cnt(
connector_object,
x,
name,
overwrite = zephyr::get_option("overwrite", "connector"),
...
)
# S3 method for class 'ConnectorLogger'
write_cnt(connector_object, x, name, ...)
Arguments
- connector_object
Connector The connector object to use.
- x
The object to write to the connection
- name
character Name of the content to read, write, or remove. Typically the table name.
- overwrite
Overwrite existing content if it exists in the connector? See connector-options for details. Default can be set globally with
options(connector.overwrite = TRUE/FALSE)
or environment variableR_CONNECTOR_OVERWRITE
.. Default:FALSE
.- ...
Additional arguments passed to the method for the individual connector.
Value
invisible connector_object.
Examples
# Write table to DBI database
cnt <- connector_dbi(RSQLite::SQLite())
cnt |>
list_content_cnt()
#> character(0)
cnt |>
write_cnt(iris, "iris")
cnt |>
list_content_cnt()
#> [1] "iris"
# Write different file types to a file storage
folder <- withr::local_tempdir("test", .local_envir = .GlobalEnv)
cnt <- connector_fs(folder)
cnt |>
list_content_cnt(pattern = "iris")
#> character(0)
# rds file
cnt |>
write_cnt(iris, "iris.rds")
# CSV file
cnt |>
write_cnt(iris, "iris.csv")
cnt |>
list_content_cnt(pattern = "iris")
#> [1] "iris.csv" "iris.rds"
# Add logging to a database connector
cnt <- connectors(data = connector_dbi(RSQLite::SQLite())) |> add_logs()
cnt$data |>
write_cnt(mtcars, "cars")
#> {"time":"2025-08-20 06:16:08","type":"write","file":"cars @ driver: SQLiteConnection, dbname: "}