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

Add fct_reordern() (Fix #16) #220

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

billdenney
Copy link
Contributor

Fix #16

@hadley, I saw what you meant in the #16 discussion about affecting the value and not just the levels. That is addressed here. Also, I removed the .desc argument. Since it was both simpler and potentially friendlier to the user to leave the decreasing argument from base::order() exposed (it doesn't have the dplyr dependency to sort decreasing), I left that. And, I made the default method "radix" so that it would work with a vector of values for decreasing (something that would annoy me whenever I forgot that I needed to set the method, and it seemed like a minor wart to add an argument directly).

Anyway, let me know what you think and if I'm missing something else important.

@billdenney
Copy link
Contributor Author

The integration check is only in R 3.2, and it is that when running one of the new examples, the following error is generated:

> A <- c(3, 3, 2, 1)
> B <- c("A", "B", "C", "D")
> fct_reordern(.f = c("A", "B", "C", "D"), A, B)
Error in base::order(..., method = method) : argument lengths differ

Looking at historical documentation (https://www.rdocumentation.org/packages/base/versions/3.2.0/topics/order), order() in R 3.2.0 didn't support the method argument. Is the preference to add code to protect R 3.2 or something else?

NEWS.md Outdated Show resolved Hide resolved
R/reorder.R Outdated Show resolved Hide resolved
R/reorder.R Outdated Show resolved Hide resolved
R/reorder.R Outdated Show resolved Hide resolved
R/reorder.R Outdated Show resolved Hide resolved
tests/testthat/test-reorder.R Show resolved Hide resolved
fct_reordern(.f = f, A, B),
factor(f, levels = c("D", "C", "A", "B"))
)
expect_equal(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the tests for decreasing = TRUE because you are just testing the behaviour of an existing function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed except for one to confirm that interaction between the two works as decreasing sorting is an important behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That adds a dependency on dplyr — instead you'll need to implement a local version of desc() inside the test, e.g. desc <- function(x) -xtfrm(x)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education, I thought that since the dplyr call is in a test and dplyr is already in the DESCRIPTION Suggests field, I thought that this was OK. (Similarly, since I have it in the examples in the help, I thought that the same applied there.) I'm happy to implement that way, but my hope was that this would be simpler for the user (via help) and future maintainer (via tests) to use.

Whichever way you confirm, I'll update to that.

Copy link
Contributor Author

@billdenney billdenney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that I have addressed all comments in the update that is about to be committed.

@billdenney
Copy link
Contributor Author

@hadley, I think that I have addressed everything.

@billdenney
Copy link
Contributor Author

FYI, I have re-updated to current main and fixed all CI issues (mainly the updated issue around pkgdown changes since this PR was originally proposed).

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 this pull request may close these issues.

Feature request: Order factor by (multiple functions of) multiple variables
2 participants