
Remove content from the connector
Source:R/cnt_generics.R
, R/dbi_methods.R
, R/fs_methods.R
, and 1 more
remove_cnt.Rd
Generic implementing of how to remove content from different connectors:
ConnectorDBI: Uses
DBI::dbRemoveTable()
to remove the table from a DBI connection.
ConnectorFS: Uses
fs::file_delete()
to delete the file.
ConnectorLogger: Logs the remove operation and calls the underlying connector method.
Usage
remove_cnt(connector_object, name, ...)
# S3 method for class 'ConnectorDBI'
remove_cnt(connector_object, name, ...)
# S3 method for class 'ConnectorFS'
remove_cnt(connector_object, name, ...)
# S3 method for class 'ConnectorLogger'
remove_cnt(connector_object, name, ...)
Value
invisible connector_object.
Examples
# Remove table in a DBI database
cnt <- connector_dbi(RSQLite::SQLite())
cnt |>
write_cnt(iris, "iris") |>
list_content_cnt()
#> [1] "iris"
cnt |>
remove_cnt("iris") |>
list_content_cnt()
#> character(0)
# Remove a file from the file storage
folder <- withr::local_tempdir()
cnt <- connector_fs(folder)
cnt |>
write_cnt("this is an example", "example.txt")
#> Error: Cannot open file for writing:
#> * '/tmp/RtmpnpFke0/file210665d8eb7b/example.txt'
cnt |>
list_content_cnt(pattern = "example.txt")
#> character(0)
cnt |>
read_cnt("example.txt")
#> Error in find_file(name, root = connector_object$path): No file found or multiple files found with the same name
cnt |>
remove_cnt("example.txt")
#> Error: [ENOENT] Failed to remove '/tmp/RtmpnpFke0/file210665d8eb7b/example.txt': no such file or directory
cnt |>
list_content_cnt(pattern = "example.txt")
#> character(0)
# Add logging to a connector and remove content
folder <- withr::local_tempdir()
cnt <- connectors(data = connector_fs(folder)) |> add_logs()
cnt$data |>
write_cnt(iris, "iris.csv")
#> Error: Cannot open file for writing:
#> * '/tmp/RtmpnpFke0/file21062bd93edc/iris.csv'
cnt$data |>
remove_cnt("iris.csv")
#> Error: [ENOENT] Failed to remove '/tmp/RtmpnpFke0/file21062bd93edc/iris.csv': no such file or directory