
Read content from the connector
Source:R/cnt_generics.R
, R/dbi_methods.R
, R/fs_methods.R
read_cnt.Rd
Generic implementing of how to read content from the different connector objects:
ConnectorDBI: Uses
DBI::dbReadTable()
to read the table from the DBI connection.
ConnectorFS: Uses
read_file()
to read a given file. The underlying function used, and thereby also the arguments available through...
depends on the file extension.
Usage
read_cnt(connector_object, name, ...)
# S3 method for class 'ConnectorDBI'
read_cnt(connector_object, name, ...)
# S3 method for class 'ConnectorFS'
read_cnt(connector_object, name, ...)
Value
R object with the content. For rectangular data a data.frame.
Examples
# Read table from DBI database
cnt <- connector_dbi(RSQLite::SQLite())
cnt |>
write_cnt(iris, "iris")
cnt |>
list_content_cnt()
#> [1] "iris"
cnt |>
read_cnt("iris") |>
head()
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3.0 1.4 0.2 setosa
#> 3 4.7 3.2 1.3 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> 5 5.0 3.6 1.4 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa
# Write and read a CSV file using the file storage connector
folder <- withr::local_tempdir()
cnt <- connector_fs(folder)
cnt |>
write_cnt(iris, "iris.csv")
#> Error: Cannot open file for writing:
#> * '/tmp/RtmppxiTmW/file1fc04bc56a7d/iris.csv'
cnt |>
read_cnt("iris.csv") |>
head()
#> Error in find_file(name, root = connector_object$path): No file found or multiple files found with the same name