Skip to content
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

read_csv chokes on negatives and decimals #400

Closed
safferli opened this issue Apr 27, 2016 · 1 comment
Closed

read_csv chokes on negatives and decimals #400

safferli opened this issue Apr 27, 2016 · 1 comment

Comments

@safferli
Copy link

safferli commented Apr 27, 2016

This is probably related to #376, #308, and #358.

read_csv(2) doesn't work with decimals which are non-locale, and also on negatives.

Check the following two examples. It's temperature data for Germany. url3 is March, and some months have negative temperatures. Data is imported as character, at least preserving the negatives and decimals. A mutate(column = as.numeric(column)) "fixes" the problem. For month April data (url4), there are no negative temperatures, and the data is imported as numeric, but dropping the decimal (so, 5.6 is converted to 56).

Expected outcome: temperature data should be imported as numeric, with correct decimal and negative values.

url3 <- paste0(
  "ftp://ftp-cdc.dwd.de/pub/CDC/",
  "regional_averages_DE/monthly/air_temperature_mean/",
  "regional_averages_tm_", sprintf("%02i", 3), ".txt"
)
url4 <- paste0(
  "ftp://ftp-cdc.dwd.de/pub/CDC/",
  "regional_averages_DE/monthly/air_temperature_mean/",
  "regional_averages_tm_", sprintf("%02i", 4), ".txt"
)

## note: ignore the parsing warnings, it's the last line that is messing it up. Can be avoided by setting n_max
dd3 <- read_csv2(url3, skip = 1, dec = ".")# temp data is as expected, but as.character(): "x.y" 
dd4 <- read_csv2(url4, skip = 1, dec = ".")# temp data is messed up: xxx

I "fixed" it by using read_lines and piping that into read.csv2(text = read_lines(...), dec = ".", ...), so that could be used as a test-case.

@hadley
Copy link
Member

hadley commented Jun 1, 2016

Duplicate of #308

@hadley hadley closed this as completed Jun 1, 2016
@lock lock bot locked and limited conversation to collaborators Sep 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants