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

last2() doesn't handle missings in y #303

Closed
hadley opened this issue Mar 22, 2022 · 2 comments · Fixed by #306
Closed

last2() doesn't handle missings in y #303

hadley opened this issue Mar 22, 2022 · 2 comments · Fixed by #306

Comments

@hadley
Copy link
Member

hadley commented Mar 22, 2022

Maybe should be more like this?

last2 <- function (x, y) {
  miss <- is.na(x) | is.na(y)
  x <- x[!miss]
  y <- y[!miss]
  y[order(x)][length(y)]
}
@DanChaltiel
Copy link

This would not be an expected behavior IMHO, as the last value of y ordered by x can totally be NA.

However, it would be quite handy to have a na.rm option in the function. This would avoid some breaking changes too.

@hadley
Copy link
Member Author

hadley commented May 17, 2022

The point of last2() is to support fct_reorder2() which aims to order the legend in the same way as the lines on on far right of the plot. A point with missing y isn't drawn, so I think it should be ignored.

hadley added a commit that referenced this issue May 17, 2022
Fixes #303

Merge commit 'f22d91f23e5fdfc1265b6cd3685dd5e3b31967a2'
hadley added a commit that referenced this issue May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants