Learn R Programming

connector (version 1.0.0)

download_cnt: Download content from the connector

Description

Generic implementing of how to download files from a connector:

  • ConnectorFS: Uses fs::file_copy() to copy a file from the file storage to the desired file.

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

Usage

download_cnt(connector_object, src, dest = basename(src), ...)

# S3 method for ConnectorFS download_cnt(connector_object, src, dest = basename(src), ...)

# S3 method for ConnectorLogger download_cnt(connector_object, src, dest = basename(src), ...)

Value

invisible connector_object.

Arguments

connector_object

Connector The connector object to use.

src

character Name of the content to read, write, or remove. Typically the table name.

dest

character Path to the file to download to or upload from

...

Additional arguments passed to the method for the individual connector.

Examples

Run this code
# Download file from a file storage

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

cnt <- connector_fs(folder)

cnt |>
  write_cnt("this is an example", "example.txt")

list.files(pattern = "example.txt")

cnt |>
  download_cnt("example.txt")

list.files(pattern = "example.txt")
readLines("example.txt")

cnt |>
  remove_cnt("example.txt")

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

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

cnt$data |>
  write_cnt(iris, "iris.csv")

cnt$data |>
  download_cnt("iris.csv", tempfile(fileext = ".csv"))

Run the code above in your browser using DataLab