library(readr)
csv <- 'x,y
"1","N/A"
"N/A","2"
'
df <- read_csv(csv, col_types = "ii", na=c("\"N/A\"", "N/A"))
Running this yields:
> df <- read_csv(csv, col_types = "ii", na=c("\"N/A\"", "N/A"))
Warning: 2 parsing failures.
row col expected actual
1 y an integer N/A
2 x an integer N/A
Practically, the "N/A"
values end up as NA
, but is there a more elegant way to handle this? For example, this runs without issues, illustrating the desired behaviour.
csv2 <- 'x,y
"1",N/A
N/A,"2"
'
df2 <- read_csv(csv2, col_types = "ii", na="N/A")