RSQLite icon indicating copy to clipboard operation
RSQLite copied to clipboard

feature request: allow quote= parameter in dbWriteTable S4 method 'SQLiteConnection,character,character'

Open ajdamico opened this issue 7 years ago • 2 comments

hi, if i'm understanding things correctly, any values that match sep= inside a quoted field will derail a dbWriteTable() import from a file connection?

library(DBI)
tf <- tempfile()

x <- c( '"header1","header2"' , '"one,two","three"' )
writeLines( x , tf )
db <- dbConnect( RSQLite::SQLite() )

# works as expected
read.csv( tf )

# fails
dbWriteTable( db , 'x' , tf )

and delimited files with quotes carry those quotes into the column values.. thanks for considering this!

y <- c( '"header1","header2"' , '"onetwo","three"' )
writeLines( y , tf )
dbWriteTable( db , 'y' , tf )

# with quotes
dbReadTable( db , 'y' )[1,1]

# without quotes
read.csv( tf )[1,1]

ajdamico avatar Jan 23 '18 15:01 ajdamico

Thanks. The code that implements this is "legacy" C code (taken from SQLite's shell.c), and there's no support for quoting in that code. Please load the data into a data frame and use the data frame method for now.

We could e.g. take code from readr and adapt it to store data in the database, avoiding the roundtrip to R.

krlmlr avatar Apr 30 '18 22:04 krlmlr

I'm open to including better CSV import in RSQLite, I don't have the bandwidth to add it myself.

krlmlr avatar Dec 27 '20 09:12 krlmlr