nrow returns NULL for a simulated source?

198 views
Skip to first unread message

Michael Sumner

unread,
Feb 20, 2018, 10:39:14 PM2/20/18
to manipulatr
I'm trying to understand tbl_lazy and op_vars behaviour. 

I expect that nrow() should return NA for a simulated source, but we get NULL

library(dbplyr)
library(dplyr)
## example data 
df <- tibble::tibble(apples = 1:3, oranges = c("a", "b", "c"))
## example SQLite db
db <- src_sqlite(tempfile(), create = TRUE)

## a real SQLite tbl
real_tbl <- copy_to(db, df)
## a simulated SQLite tbl
sim_tbl <- tbl_lazy(df, simulate_sqlite())

## NA, as expected
nrow(real_tbl)
## NULL, not expected
nrow(sim_tbl)


My question is, should nrow(real_tbl) return NA? How does that work though, I'm confused about the ops_ control here. 


The problem comes with the print: 

## this causes printing to fail in trunc_mat
print(sim_tbl)
#Error in if (is.na(rows) || rows > tibble_opt("print_max")) { : 
#    missing value where TRUE/FALSE needed
#  In addition: Warning message:
#    In is.na(rows) : is.na() applied to non-(list or vector) of type 'NULL'

## though other ops do work
str(op_base(real_tbl, "apples"))
str(op_base(sim_tbl, "apples"))

Michael Sumner

unread,
Feb 20, 2018, 10:41:16 PM2/20/18
to manipulatr
Oh, I forgot about the new site!

I'll ask on RStudio community, thanks

Michael Sumner

unread,
Feb 21, 2018, 3:44:37 AM2/21/18
to manipulatr
Reply all
Reply to author
Forward
0 new messages