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

Errors in fct_reorder2 documentation #352

Open
AlexJHomer opened this issue Jun 24, 2023 · 0 comments
Open

Errors in fct_reorder2 documentation #352

AlexJHomer opened this issue Jun 24, 2023 · 0 comments

Comments

@AlexJHomer
Copy link

forcats/R/reorder.R

Lines 9 to 11 in 4a8525a

#' @param .x,.y The levels of `f` are reordered so that the values
#' of `.fun(.x)` (for `fct_reorder()`) and `fun(.x, .y)` (for `fct_reorder2()`)
#' are in ascending order.

The phrase "ascending order" is misleading, since for fct_reorder2 the default is to use descending order instead, and in any case the direction is controlled by the .desc argument.

f <- factor(c("a", "a", "b"))
f
#> [1] a a b
#> Levels: a b

x <- c(1, 2, 3)
y <- c(2, 4, 6)
fun <- \(x, y) mean(x + y)

# fun gives a lower value for "a" than for "b":
fun(x[f == "a"], y[f == "a"])
#> [1] 4.5
fun(x[f == "b"], y[f == "b"])
#> [1] 9

forcats::fct_reorder2(f, x, y, fun)
#> [1] a a b
#> Levels: b a

Created on 2023-06-24 with reprex v2.0.2

Less crucially, it should read `.fun(.x, .y)` instead of `fun(.x, .y)`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants