1

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)"))

ロードが一重引用符を正しく解析できないのはなぜですか? 元のファイルから一重引用符を削除しない回避策は何ですか?

4

0 に答える 0