Learn R Programming

connector (version 0.1.0)

tbl_cnt: Use dplyr verbs to interact with the remote database table

Description

Generic implementing of how to create a dplyr::tbl() connection in order to use dplyr verbs to interact with the remote database table. Mostly relevant for DBI connectors.

  • ConnectorDBI: Uses dplyr::tbl() to create a table reference to a table in a DBI connection.

  • ConnectorFS: Uses read_cnt() to allow redundancy between fs and dbi.

Usage

tbl_cnt(connector_object, name, ...)

# S3 method for ConnectorDBI tbl_cnt(connector_object, name, ...)

# S3 method for ConnectorFS tbl_cnt(connector_object, name, ...)

Value

A dplyr::tbl object.

Arguments

connector_object

Connector The connector object to use.

name

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

...

Additional arguments passed to the method for the individual connector.

Examples

Run this code
# Use dplyr verbs on a table in a DBI database
cnt <- connector_dbi(RSQLite::SQLite())

iris_cnt <- cnt |>
  write_cnt(iris, "iris") |>
  tbl_cnt("iris")

iris_cnt

iris_cnt |>
  dplyr::collect()

iris_cnt |>
  dplyr::group_by(Species) |>
  dplyr::summarise(
    n = dplyr::n(),
    mean.Sepal.Length = mean(Sepal.Length, na.rm = TRUE)
  ) |>
  dplyr::collect()

# Use dplyr verbs on a table

folder <- withr::local_tempdir()
cnt <- connector_fs(folder)

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

iris_cnt <- cnt |>
  tbl_cnt("iris.csv")

iris_cnt

iris_cnt |>
  dplyr::group_by(Species) |>
  dplyr::summarise(
    n = dplyr::n(),
    mean.Sepal.Length = mean(Sepal.Length, na.rm = TRUE)
  )

Run the code above in your browser using DataLab