This R6 class is a general class for all connectors. It is used to define the methods that all connectors should have. New connectors should inherit from this class, and the methods described below should be implemented.
See also
vignette("customize")
on how to create custom connectors and methods,
and concrete examples in connector_fs and connector_dbi.
Methods
Method new()
Initialize the connector with the option of adding an extra class.
Usage
connector$new(extra_class = NULL)
Arguments
extra_class
character Extra class to assign to the new connector.
Method print()
Print method for a connector showing the registered methods and specifications from the active bindings.
Returns
invisible self.
Method list_content_cnt()
List available content from the connector. See also list_content_cnt.
Returns
A character vector of content names
Method read_cnt()
Read content from the connector. See also read_cnt.
Arguments
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.
Returns
R object with the content. For rectangular data a data.frame.
Method write_cnt()
Write content to the connector.See also write_cnt.
Arguments
x
The object to write to the connection
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.
Returns
invisible self.
Method remove_cnt()
Remove or delete content from the connector. See also remove_cnt.
Arguments
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.
Returns
invisible self.
Examples
# Create connector
cnt <- connector$new()
cnt
#> <connector>
# Standard error message if no method is implemented
cnt |>
read_cnt("fake_data") |>
try()
#> Error in read_cnt(cnt, "fake_data") :
#> Method not implemented for class <connector/R6>
#> ℹ See the customize (`vignette(connector::customize)`) vignette on how to
#> create custom connectors and methods
# Connection with extra class
cnt_my_class <- connector$new(extra_class = "my_class")
cnt_my_class
#> <my_class/connector>
# Custom method for the extra class
read_cnt.my_class <- function(connector_object) "Hello!"
registerS3method("read_cnt", "my_class", "read_cnt.my_class")
cnt_my_class
#> <my_class/connector>
#> Registered methods:
#> • `read_cnt.my_class()`
read_cnt(cnt_my_class)
#> [1] "Hello!"