Example:
x <- data.frame(X = c("",""), Y=1:2, stringsAsFactors = F)
write.csv("/tmp/temp.txt", row.names=F, quote=T)
read.csv("/tmp/temp.txt")
X Y
1 NA 1
2 NA 2
readr::read_csv("/tmp/temp.txt", col_types = list(col_character(), col_double()))
X Y
<chr> <dbl>
1 NA 1
2 NA 2
I expect the X column to be empty strings, but it is converted to NA_logical_
despite being a field that has quotation marks (quote=T
). I can find no parameter that lets me read the X column as empty strings. The problem occurs for data.table
and readr
too.
Why does this happen?
Edit: I'm mostly looking for an explanation why this happens, not a solution.