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.