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

Hybrid version of max(NA_real_, na.rm = TRUE) returns NA #2305

Closed
krlmlr opened this issue Dec 10, 2016 · 3 comments
Closed

Hybrid version of max(NA_real_, na.rm = TRUE) returns NA #2305

krlmlr opened this issue Dec 10, 2016 · 3 comments
Assignees
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@krlmlr
Copy link
Member

krlmlr commented Dec 10, 2016

data_frame(a = NA_real_) %>% summarise(a = max(a, na.rm = TRUE))
## # A tibble: 1 × 1
##       a
##   <dbl>
## 1    NA
@krlmlr krlmlr added bug an unexpected problem or unintended behavior data frame labels Dec 10, 2016
@krlmlr krlmlr self-assigned this Feb 10, 2017
@krlmlr krlmlr modified the milestone: data frame 1 Feb 10, 2017
@krlmlr
Copy link
Member Author

krlmlr commented Feb 19, 2017

@hadley: I wonder what the behavior of the following should be:

data_frame(a = NA_integer_) %>% summarise(a = max(a, na.rm = TRUE))
data_frame(a = integer()) %>% summarise(a = max(a))

Current code sets a to NA_integer_. It would be more consistent with base R to return -Inf instead, but this requires promoting to numeric.

@hadley
Copy link
Member

hadley commented Feb 19, 2017

Does base R always return a numeric? That might be a consistent principle. What does/should max(NA) return?

@krlmlr
Copy link
Member Author

krlmlr commented Feb 19, 2017

max(int_arg) returns an integer in base R.

The hybrid version of max(NA_integer_) returns NA_integer_, with both na.rm = TRUE or = FALSE.

krlmlr added a commit to krlmlr/dplyr that referenced this issue Feb 19, 2017
krlmlr added a commit to krlmlr/dplyr that referenced this issue Feb 19, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants