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

numeric overflow might need warning #1108

Closed
ajdamico opened this issue Apr 27, 2015 · 3 comments
Closed

numeric overflow might need warning #1108

ajdamico opened this issue Apr 27, 2015 · 3 comments
Assignees
Milestone

Comments

@ajdamico
Copy link
Contributor

@ajdamico ajdamico commented Apr 27, 2015

reproducible example

library(dplyr)
library(readr)

tf <- tempfile()
download.file( "http://downloads.cms.gov/FILES/HCRIS/HOSP10FY2013.zip" , tf , mode = 'wb' )


z <- unzip( tf , exdir = tempdir() )
nmrc <- read_csv( grep( 'NMRC' , z , value = TRUE ) , col_names = F )

# Warning message:
# In sum(nmrc$X5, na.rm = TRUE) : integer overflow - use sum(as.numeric(.))
sum( nmrc$X5 , na.rm = TRUE )

# now it works
sum( as.numeric( nmrc$X5 ) , na.rm = TRUE )

# this sum is missing despite the na.rm = TRUE
nmrc %>% summarize( mean( X5 , na.rm = TRUE ) , sum( X5 , na.rm = TRUE ) )

# here's the fix for this case
nmrc$X6 <- as.numeric( nmrc$X5 )
nmrc %>% summarize( mean( X6 , na.rm = TRUE ) , sum( X6 , na.rm = TRUE ) )
@hadley hadley added this to the 0.4.2 milestone May 19, 2015
@hadley
Copy link
Member

@hadley hadley commented May 19, 2015

@romainfrancois could you please take a look? If it's a lot of work we can push off until 0.5

@hadley hadley added this to the 0.5 milestone May 21, 2015
@hadley hadley removed this from the 0.4.2 milestone May 21, 2015
@hadley
Copy link
Member

@hadley hadley commented May 21, 2015

Need to get 0.4.2 out ASAP for CRAN, so lets push this off

@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Jul 8, 2015

Now getting:

> nmrc %>% summarize( mean( X5 , na.rm = TRUE ) , sum( X5 , na.rm = TRUE ) )
Source: local data frame [1 x 2]

  mean(X5, na.rm = TRUE) sum(X5, na.rm = TRUE)
1                7152239                    NA
Warning message:
In summarise_impl(.data, dots) : integer overflow - use sum(as.numeric(.))

The alternative would be I guess to automatically promote the result to a numeric vector. We do calculate the double anyway, but when we see that it can't fit an int we just go with NA.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants