last2() doesn't handle missings in y
hadley opened this issue · 2 comments
hadley commented
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 commented
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 commented
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.