Skip to content

Automatically add more subclasses to tbl() inferred class? #1597

@MichaelChirico

Description

@MichaelChirico

subclass <- class(src$con)[[1]] # prefix added by dplyr::make_tbl

We have a DBIConnection class that inherits from a virtual class:

is(con)
# [1] "MyDBIConnection"        "VirtualDBIConnection" "DBIConnection"          "DBIObject"

We had to write a tbl.MyDBIConnection in order to get the desired class structure of the output:

tbl.MyDBIConnection <- function(src, from, ...) {
  dbi_src <- src_dbi(src, auto_disconnect = FALSE)
  tbl <- tbl_sql(c("MyDBIConnection", "VirtualDBIConnection", "dbi"), src = dbi_src, from = from, ...)
  return(tbl)
}

It seems we could instead try to do this automatically:

tbl.src_dbi <- function(src, from, ...) {
  inheritance <- is(src$con)
  subclass <- head(inherits, match("DBIConnection", inheritance)-1L) # prefix added by dplyr::make_tbl
  tbl_sql(c(subclass, "dbi"), src = src, from = from, ...)
}

However I'm not sure the broader implications of this (do we require src$con to be S4? do we require it to inherit from DBIConnection?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions