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

Specifying col_numeric or "n" for col_types causes negative signs to be dropped #350

Closed
ateucher opened this issue Jan 8, 2016 · 1 comment

Comments

@ateucher
Copy link

ateucher commented Jan 8, 2016

Specifying col_numeric or "n" for col_types causes absolute values to be taken (negative signs are ignored).

library(readr)

df <- data.frame(Col1 = c("a", "b", "c", "d", "e", "f"), 
                 Col2 = c(1.2, 2, -3.5, 0, -2.6, 5))

write_csv(df, "test.csv")

## Read with no specification of col_types (works as expected)
read_csv("test.csv")
##   Col1 Col2
## 1    a  1.2
## 2    b  2.0
## 3    c -3.5
## 4    d  0.0
## 5    e -2.6
## 6    f  5.0
## Specifying double (works as expected)
read_csv("test.csv", col_types = "cd")
##   Col1 Col2
## 1    a  1.2
## 2    b  2.0
## 3    c -3.5
## 4    d  0.0
## 5    e -2.6
## 6    f  5.0
## Specifying number (drops negatives)
read_csv("test.csv", col_types = "cn")
##   Col1 Col2
## 1    a  1.2
## 2    b  2.0
## 3    c  3.5
## 4    d  0.0
## 5    e  2.6
## 6    f  5.0
## Specifying number with cols (drops negatives)
read_csv("test.csv", col_types = cols(Col1 = col_character(), Col2 = col_number()))
##   Col1 Col2
## 1    a  1.2
## 2    b  2.0
## 3    c  3.5
## 4    d  0.0
## 5    e  2.6
## 6    f  5.0
sessionInfo()
## R version 3.2.3 (2015-12-10)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 7 x64 (build 7601) Service Pack 1
## 
## locale:
## [1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252   
## [3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                   
## [5] LC_TIME=English_Canada.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] readr_0.2.2
## 
## loaded via a namespace (and not attached):
##  [1] magrittr_1.5    tools_3.2.3     htmltools_0.3   yaml_2.1.13    
##  [5] Rcpp_0.12.2     stringi_1.0-1   rmarkdown_0.9.2 knitr_1.12     
##  [9] stringr_1.0.0   digest_0.6.9    evaluate_0.8
@hadley
Copy link
Member

hadley commented Jun 2, 2016

Duplicate of #308

@hadley hadley closed this as completed Jun 2, 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