-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currency parser #444
Comments
I looked into this a little bit and full currency parsing is a bit tricky because of the combination of options. Worth considering though |
I just needed this, trying to import csv's on my kids' transit usage. Most of the transactions are negative. They are formatted like so: |
I, too, would like to parse negative currency values. Perhaps there's an intermediate solution that handles the negative sign outside the currency sign that doesn't require full international currency standards support? |
I also just needed this, getting data out of a website where values are stored as I also wondered if it would be possible to leave the value as is if conversion can't be done, as opposed to converting into |
The best bet for now is to parse these columns as characters and do the parsing in R yourself. Something like |
Right, there are workarounds once you realize what the issue is. A more realistic situation where this comes up is something like the following. library(tidyverse)
df <- tibble(
x = c("-$12,500", "$2,000", "-$5,000", "$1,000", "-$3,000")
)
df %>%
mutate(x = parse_number(x))
#> Warning: 3 parsing failures.
#> row col expected actual
#> 1 -- a number -
#> 3 -- a number -
#> 5 -- a number -
#> # A tibble: 5 x 1
#> x
#> <dbl>
#> 1 NA
#> 2 2000
#> 3 NA
#> 4 1000
#> 5 NA but imagine the dataset is much larger. If there was some visual indication of the original values in the warning, it would be easier to spot the issue. Of course, any change to the warning here would require similar changes to other |
Oh, that was actually due to a (likely long standing) bug, the library(tidyverse)
df <- tibble(
x = c("-$12,500", "$2,000", "-$5,000", "$1,000", "-$3,000")
)
df %>%
mutate(x = parse_number(x))
#> Warning: 3 parsing failures.
#> row col expected actual
#> 1 -- a number -$12,500
#> 3 -- a number -$5,000
#> 5 -- a number -$3,000
#> # A tibble: 5 x 1
#> x
#> <dbl>
#> 1 NA
#> 2 2000
#> 3 NA
#> 4 1000
#> 5 NA Created on 2019-10-24 by the reprex package (v0.3.0) |
Thank you @jimhester! |
This seems unlikely to be done by us in the near future, so will close this issue. |
As mentioned in #308 (comment) we do not support negative currencies for parse number
Perhaps we should have a
parse_currency()
andcol_currency()
which would be locale aware to handle this and other cases.The text was updated successfully, but these errors were encountered: