Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot write tbl_df to SQLite database #317

Closed
leeper opened this issue Nov 16, 2015 · 6 comments
Closed

Cannot write tbl_df to SQLite database #317

leeper opened this issue Nov 16, 2015 · 6 comments

Comments

@leeper
Copy link
Contributor

leeper commented Nov 16, 2015

I'm trying to create an SQLite database (using RSQLite), but it's giving an error when trying to write a data.frame read in using readr::read_fwf due to the "tbl_df" class:

library("readr")
library("RSQLite")
fwf_sample <- system.file("extdata/fwf-sample.txt", package = "readr")
d1 <- read_fwf(fwf_sample, fwf_widths(c(2, 5, 3)))
db <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(conn = db, name = "table", value = d1)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for functiondbWriteTablefor signature"SQLiteConnection", "character", "tbl_df"

Appears to be same issue as: r-dbi/RSQLite#82

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RSQLite_1.0.0 DBI_0.3.1     readr_0.2.2  

loaded via a namespace (and not attached):
[1] tools_3.2.3 Rcpp_0.12.4
@krlmlr
Copy link
Member

krlmlr commented Mar 29, 2016

Should be fixed with the tibble package.

@leeper
Copy link
Contributor Author

leeper commented Mar 29, 2016

@krlmlr In what sense?

@krlmlr
Copy link
Member

krlmlr commented Mar 29, 2016

tibble calls setOldClass(), R takes care of the rest.

(Of course, it must be loaded, which doesn't happen automatically yet.)

@leeper
Copy link
Contributor Author

leeper commented Mar 29, 2016

@krlmlr So, in the example (I just updated to make it fully reproducible), what steps do I have to add to make this work?

@krlmlr
Copy link
Member

krlmlr commented Mar 29, 2016

requireNamespace("tibble")

but this actually should be done by the package itself.

@krlmlr
Copy link
Member

krlmlr commented Mar 29, 2016

...or use devtools::install_github("hadley/readr#385").

@hadley hadley closed this as completed in 8312374 Jun 2, 2016
@hadley hadley removed the in progress label Jun 2, 2016
@lock lock bot locked and limited conversation to collaborators Sep 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants