Skip to contents

Generic implementing of how to write content to the different connector objects:

  • connector_fs: 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.

Usage

write_cnt(connector_object, x, name, ...)

# S3 method for class 'connector_dbi'
write_cnt(connector_object, x, name, overwrite = TRUE, ...)

# S3 method for class 'connector_fs'
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.

...

Additional arguments passed to the method for the individual connector.

overwrite

By default set to TRUE, in order to allow interchangeability between how connector_fs works and connector_dbi.

Value

invisible connector_object.

Examples

# Write table to DBI database
cnt <- connector_dbi$new(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
cnt <- connector_fs$new(tempdir())

cnt |>
  list_content_cnt(pattern = "iris")
#> [1] "iris.csv"             "iris.rds"             "iris203d6e19f9b3.csv"

# 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"             "iris203d6e19f9b3.csv"