I'm trying to run the following command in R in order to read a local tab-delimited file as a SQLite database:
library(RSQLite)
banco <- dbConnect(drv = "SQLite",
dbname = "data.sqlite")
dbWriteTable(conn = banco,
name = "Tarefas",
value = "data.tsv",
sep = "\t",
dec = ",",
na.strings = c("", NA),
row.names = FALSE,
header = TRUE)
However, the statements above yield the following error:
Error in read.table(fn, sep = sep, header = header, skip = skip, nrows = nrows, : formal argument "na.strings" matched by multiple actual arguments
Which makes me think I'm not being able to pass na.strings
explicitly as a read.delim
argument. Running dbWriteTable
without this argument gives me "RS-DBI driver: (RS_sqlite_import: ./data.tsv line 17696 expected 20 columns of data but found 18)". This is understandable, since I've checked line 17696 and it is almost completely blank.
Another test run using sqldf
also gives me an error:
> read.csv2.sql(file = "data.tsv",
+ sql = "CREATE TABLE Tarefas AS SELECT * FROM FILE LIMIT 5",
+ dbname = "data.sqlite",
+ header = TRUE,
+ row.names = FALSE)
Error in sqliteExecStatement(con, statement, bind.data) :
RS-DBI driver: (error in statement: no such table: FILE)
Which I believe is an unrelated error, but still very confusing for someone who's pretty much an absolute SQL noob such as myself. Runnin read.csv.sql
instead gives me this error:
Error in read.table(fn, sep = sep, header = header, skip = skip, nrows = nrows, : more columns than column names
So is there a way to pass na.strings = c("", NA)
at dbWriteTable
? Is there a better way to read 10 GB tab-delimited files into R aside from sqldf
and RSQLite
? I've already tried data.table
and ff
.