I would like to read a binary field from an sqlite database from R.
I succeeded with an indirect method, consisting in first exporting the binary field in a temporary file, via a shell command invoking sqlite3 and then reading this binary file with the readbin() command. Here is the detailed code:
library(RSQLite)
fileConn<-file("script.sql")
writeLines(c('.load fileio.dll','SELECT writefile("tmp.bin",Curve) FROM Table1 WHERE Id=41;','.exit'), fileConn)
close(fileConn)
shell('sqlite3.exe database.sqlite < script.sql')
to.read<-file(description="tmp.bin","rb")
tmp<-readBin(to.read,"integer",n=10000,size=2)
plot(tmp)
close(to.read)
I want to directly read the binary field with R, without creating a temporary file via sqlite3.
According to suggestions (thanks a lot for that !), I tried the following:
con <- dbConnect(SQLite(),dbname="database.sqlite")
tmp<-dbGetQuery(con,"SELECT quote(Curve) FROM Table1 WHERE Id=41")
tmp
which retruns:
quote(Curve)
1 '\023'
It doesn't looks good, as I am supposed to get a vector of 870 integer elements, starting with :
head(good)
[1] 19 19 0 19 19 19
What's going wrong with my sql statement ? How can I directly read the binary field with R ?
Thank you very much in advance