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

View source: R/cnt_generics.R

tbl_cntR Documentation

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 class 'ConnectorDBI'
tbl_cnt(connector_object, name, ...)

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

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.

Value

A dplyr::tbl object.

Examples

# 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)
  )


connector documentation built on June 8, 2025, 11:36 a.m.