is_tbl does not work correctly with lazy evaluation

Issue #30 new
Andrew Leonard created an issue

The function checks if the object is a data.frame before it checks if the object is a tbl and ultimately returns the incorrect value - here’s an example:

library(DBI)
library(dplyr)
library(assertive)

.data <- data.frame(A = rep(LETTERS[1:3], 3), B = sample(9))
conn <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(conn, "table1", .data)

query <- "select * from table1"
.tbl <- tbl(conn, sql(query))

dplyr::is.tbl(.tbl)
# [1] TRUE

assertive::is_tbl(.tbl)
# [1] FALSE
# Cause of failure:  .tbl is not of class 'data.frame'; it has class 'tbl_SQLiteConnection, 
# tbl_dbi, tbl_sql, tbl_azy, tbl'.

Possible solution:

# Original is_tbl function:
function (x, .xname = get_name_in_parent(x))
{
  if (!(ok <- is_data.frame(x, .xname))) {
    return(ok)
  }
  is2(x, "tbl", .xname)
}

# Possible solution?
function (x, .xname = get_name_in_parent(x))
{
  is2(x, "tbl", .xname)
}

Comments (0)

  1. Log in to comment