Home > Mobile >  DBConnect to open SQLite in read-only mode in R
DBConnect to open SQLite in read-only mode in R

Time:02-09

I'm working on converting a simple Python script to R to act as a template for connecting up to SQLite files. The data is on a NFS mount, and we've run into a few snags in setting up the original Python template (namely, IO errors), but we were able to work around them by connecting with read-only mode and setting the VFS to unix-none, e.g.:

# Python version
path = "file///mnt_nfs/examplepath.edu/path/file.db"
connect = sqlite3.connect(path   "?mode=ro&vfs=unix-none", uri = True)
cur = connect.cursor()

While we know this is far from a perfect solution, it's acting as an interim solution while we set up a more robust database (so our users can still connect to their data in the meantime). However, most of our students are more familiar with R than Python, and I'm having difficulty finding how to recreate the workarounds in R. Is there some way to set dbConnect to include the read-only and unix-none arguments (or equivalent)? I have the basics, but it's throwing a similar disk IO Error as the Python code was before we added the arguments. I can't seem to find any info on it in the DBI documentation.

connect <- dbConnect(RSQLite::SQLite(), path)

CodePudding user response:

I think it is

dbConnect(SQLite(), dbname=path, flags=SQLITE_RO, vfs="unix-none")

documented at

library(RSQLite)
?`dbConnect,SQLiteDriver-method`
  •  Tags:  
  • Related