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:
connector_dbi: Uses
DBI::dbReadTable()
to read the table from the DBI connection.
connector_fs: 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 'connector_dbi'
read_cnt(connector_object, name, ...)
# S3 method for class 'connector_fs'
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$new(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
cnt <- connector_fs$new(tempdir())
cnt |>
write_cnt(iris, "iris.csv")
cnt |>
read_cnt("iris.csv") |>
head()
#> Rows: 150 Columns: 5
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): Species
#> dbl (4): Sepal.Length, Sepal.Width, Petal.Length, Petal.Width
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 6 × 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3 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 3.6 1.4 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa