1

Reprex:

con <- DBI::dbConnect(RSQLite::SQLite(), path = "test.sqlite")
dbWriteTable(con, "mtcars", mtcars)
dbListTables(con)
[1] "mtcars"
dbDisconnect(con)

When I come back:

con <- DBI::dbConnect(RSQLite::SQLite(), path = "test.sqlite")
dbListTables(con)
character(0)

I thought dbConnect should create a database if none exists. I don't know what is going on.

skurp
  • 389
  • 3
  • 13

1 Answers1

0

To create a local database you still need to supply parameters specific to your machine. This fixed the issue for me:

con <- DBI::dbConnect(RSQLite::SQLite(),
                  user = 'root',
                  password = '',
                  dbname = 'test.sqlite',
                  host = 'localhost')

This is documented poorly if you do not have much understanding of SQLite databases. It seems a database was only being created in memory. Maybe someone else can expound on this as I think warnings would help guide users in this situation.

skurp
  • 389
  • 3
  • 13
  • I don't think `user`, `password` and `host` help much here. `dbname` is the parameter to set, instead of `path`. See `?RSQLite::"dbConnect,SQLiteDriver-method"` . – krlmlr Aug 02 '18 at 20:24