edwindj / chunked

Chunkwise Text-file Processing for 'dplyr'
https://edwindj.github.io/chunked
164 stars 7 forks source link

`read_chunkwise` fails on `tbl` object #4

Closed talegari closed 7 years ago

talegari commented 7 years ago

Dear Edwin,

I encountered an error while trying to reproduce you codes on the slides(UseR! 2016) of the package on page 11 named 'Scenario 3: DB -> TXT'.

library("chunked")
library("RSQLite")

dbcon <- dbConnect(SQLite(), "test.sqlite")
dbWriteTable(dbcon, "mtcars", mtcars)
dbDisconnect(dbcon)

tbl<-
  ( src_sqlite("test.sqlite") %>%
      tbl("mtcars")
  ) %>%
  read_chunkwise(chunk_size = 10, format = "tbl") %>%
  write_chunkwise('test2.csv')

This produces the error:

Error in UseMethod("read_chunkwise") : 
  no applicable method for 'read_chunkwise' applied to an object of class "c('tbl_sqlite', 'tbl_sql', 'tbl_lazy', 'tbl')"

Reading the function read_chunkwise makes me feel that no method is present for a tbl. Am I making a mistake?

rsqlite version: 1.1.2 dplyr version: 0.5.0 chunked version: 0.3

Regards, Srikanth KS

edwindj commented 7 years ago

Dear Srikanth,

Thanks for your question:

Your script is almost correct: you should remove the line "read_chunkwise", and then it is working, since the write_chunkwise function can operate on a tbl_ object. I will update the documentation, and add functionalty so your original code will work.

library("chunked")
library("RSQLite")

dbcon <- dbConnect(SQLite(), "test.sqlite")
dbWriteTable(dbcon, "mtcars", mtcars)
dbDisconnect(dbcon)

tbl<-
  ( src_sqlite("test.sqlite") %>%
      tbl("mtcars")
  ) %>%
  write_chunkwise('test2.csv', chunk_size=10)

Best regards,

Edwin

talegari commented 7 years ago

Dear Edwin,

Thanks for the quick update! The code that produced the error now works. Cognitively, it is intuitive to set chunksize at 'read' stage.

edwindj commented 7 years ago

I agree :-)