dbWriteTable加载失败

时间:2015-08-17 18:56:22

标签: r sqlite rsqlite

我一直在观察来自DBI:::dbWriteTable的奇怪行为,这似乎与我试图读取的文件的输入字段中出现单引号有关。

这是一个可重复性最低的例子:

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",  field.types = c(V1 = "varchar(25)", V2 = "varchar(25)"))

结果:

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 1 did not have 2 elements

从每行中删除一个或两个单引号将导致成功加载:

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", field.types = c(V1 = "varchar(25)", V2 = "varchar(25)"))

为什么加载无法正确解析单引号? 不涉及从原始文件中删除单引号的解决方法是什么?

0 个答案:

没有答案