I have been observing strange behavior from DBI:::dbWriteTable which seems to be connected to the occurrences of single quotes in input fields of the files I am attempting to read in.
Here is a minimally reproducible example:
library(RSQLite)
con <- dbConnect(RSQLite::SQLite(), dbname = "test_db")
cat("Girls' Shoes\tGirls' Preschool Shoes\nGirls' Shoes\tGirls' Preschool Shoes\nEXPLORER JAKE\tEXPLORER JAKEWITH TOY\n", file = "test.dat")
dbWriteTable(con, name = "test_table", value = "test.dat", head = FALSE, sep = "\t")
results in:
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 1 did not have 2 elements
whereas eliminating one or both single quotes from each line will result in a successful load:
cat("Girls' Shoes\tGirls Preschool Shoes\nGirls Shoes\tGirls' Preschool Shoes\nEXPLORER JAKE\tEXPLORER JAKEWITH TOY\n", file = "test.dat")
dbRemoveTable(con, name = "test_table")
dbWriteTable(con, name = "test_table", value = "test.dat", head = FALSE, sep = "\t")
Why is the load failing to parse the single quotes correctly? What is a workaround that does not involve removing the single quotes from the original file?
Aucun commentaire:
Enregistrer un commentaire