Search code examples
rsqlitedbivacuum

How to vacuum an sqlite database within R?


I have created and filled a sqlite database within R using packages DBI and RSQLite. E.g. like that:

con_sqlite <- DBI::dbConnect(RSQLite::SQLite(), "../mydatabase.sqlite")
DBI::dbWriteTable(con_sqlite, "mytable", d_table, overwrite = TRUE)
...

Now the sqlite file got too big and I reduced the tables. However, the size does not decrease and I found out that I have to use command vaccum. Is there a possibility to use this command within R?


Solution

  • I think this should do the trick:

    DBI::dbExecute(con, "VACUUM;")