R/cnt_generics.R
, R/dbi_methods.R
, R/fs_methods.R
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.
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"),
...
)
Connector The connector object to use.
The object to write to the connection
character Name of the content to read, write, or remove. Typically the table name.
Overwrite existing content if it exists in the connector?. Default: FALSE
.
Additional arguments passed to the method for the individual connector.
invisible connector_object.
# 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()
cnt <- connector_fs(folder)
cnt |>
list_content_cnt(pattern = "iris")
#> character(0)
# rds file
cnt |>
write_cnt(iris, "iris.rds")
#> Warning: cannot open file '/tmp/RtmpWV8S1R/fileb9b422f4baa25/iris.rds': No such file or directory
#> Error in saveRDS(x, con, version = version, refhook = refhook, ascii = text): cannot open the connection
# CSV file
cnt |>
write_cnt(iris, "iris.csv")
#> Error: Cannot open file for writing:
#> * '/tmp/RtmpWV8S1R/fileb9b422f4baa25/iris.csv'
cnt |>
list_content_cnt(pattern = "iris")
#> character(0)