0
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")  
Ian Gow
  • 2,036
  • 1
  • 18
  • 26
  • I get some warning in the first case, but it reads it as NA. – akrun Jul 16 '16 at 05:32
  • I know it ends up as `NA`. But when I see `Warning: 296656 parsing failures`, it would be nice to suppress the warnings for non-issues (i.e., `"N/A"` being converted to `NA`). – Ian Gow Jul 16 '16 at 05:34
  • 1
    I don't know whether it is possible within the `read_csv`, but you can do `read_csv(gsub('"', "", csv), col_types = "ii", na = "N/A")` – akrun Jul 16 '16 at 06:29

1 Answers1

0

It turns out that this is a known issue that has been addressed in the (current) development version of readr. So doing this addresses the issue:

library(devtools)
install_github("hadley/readr")
Ian Gow
  • 2,036
  • 1
  • 18
  • 26