Learn R Programming

connector (version 1.0.0)

upload_cnt: Upload content to the connector

Description

Generic implementing of how to upload files to a connector:

  • ConnectorLogger: Logs the upload operation and calls the underlying connector method.

Usage

upload_cnt(
  connector_object,
  src,
  dest = basename(src),
  overwrite = zephyr::get_option("overwrite", "connector"),
  ...
)

# S3 method for ConnectorFS upload_cnt( connector_object, src, dest = basename(src), overwrite = zephyr::get_option("overwrite", "connector"), ... )

# S3 method for ConnectorLogger upload_cnt( connector_object, src, dest = basename(src), overwrite = zephyr::get_option("overwrite", "connector"), ... )

Value

invisible connector_object.

Arguments

connector_object

Connector The connector object to use.

src

character Path to the file to download to or upload from

dest

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 variable R_CONNECTOR_OVERWRITE.. Default: FALSE.

...

Additional arguments passed to the method for the individual connector.

Examples

Run this code
# Upload file to a file storage

writeLines("this is an example", "example.txt")

folder <- withr::local_tempdir("test", .local_envir = .GlobalEnv)

cnt <- connector_fs(folder)

cnt |>
  list_content_cnt(pattern = "example.txt")

cnt |>
  upload_cnt("example.txt")

cnt |>
  list_content_cnt(pattern = "example.txt")

cnt |>
  remove_cnt("example.txt")

file.remove("example.txt")

# Add logging to a file system connector for uploads
folder <- withr::local_tempdir("test", .local_envir = .GlobalEnv)

cnt <- connectors(data = connector_fs(folder)) |> add_logs()

# Create a temporary file
temp_file <- tempfile(fileext = ".csv")
write.csv(iris, temp_file, row.names = FALSE)

cnt$data |>
  upload_cnt(temp_file, "uploaded_iris.csv")

Run the code above in your browser using DataLab