0

Is there a way to get readr to parse numbers in parenthesis as negative numbers? For example, in the code below I would like column B to be parsed as numbers and for the first item to be -2.3.

library(readr)

data <- "A,B,C
1, (2.3), 4
2, 4.6, 7.1"

# B is parsed as chr
read_csv(data)

# B is parsed as a double, but (2.3) is interpreted as positive
read_csv(data, col_types = cols(B = col_number()))

Currently I simply read as character data and then post-process, but I would prefer to (say) register a custom parser.

banbh
  • 1,331
  • 1
  • 13
  • 31
  • 1
    Maybe you can check the answer to this question: http://stackoverflow.com/questions/5068705/processing-negative-number-in-accounting-format – Romain Oct 27 '16 at 19:24
  • @Romain That post is useful, but does not use `readr`. Ideally, I would like to keep using `readr`. – banbh Oct 27 '16 at 19:49
  • Nope. Readr can't be trusted with [negative currencies.](https://github.com/tidyverse/readr/issues/308) There was some talk about fixing the parser, but [nothing done yet.](https://github.com/tidyverse/readr/issues/444) It seems to me like kind of a big deal. – Nettle Dec 17 '17 at 14:31

0 Answers0