Skip to content

Commit

Permalink
ARROW-13125: [R] Throw error when 2+ args passed to desc() in arrange()
Browse files Browse the repository at this point in the history
This throws an error if the user passes two or more arguments to `desc()` in `arrange()`. Previously the second argument was silently ignored. The zero-arguments case is already handled.

Closes apache#10559 from ianmcook/ARROW-13125

Authored-by: Ian Cook <[email protected]>
Signed-off-by: Ian Cook <[email protected]>
  • Loading branch information
ianmcook committed Jun 25, 2021
1 parent c4a20e9 commit dedcbc0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion r/R/dplyr-arrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ find_and_remove_desc <- function(quosure) {
# remove enclosing parentheses
expr <- expr[[2]]
} else if (identical(expr[[1]], quote(desc))) {
# ensure desc() has only one argument (when an R expression is a function
# call, length == 2 means it has exactly one argument)
if (length(expr) > 2) {
stop("desc() expects only one argument", call. = FALSE)
}
# remove desc() and toggle descending
expr <- expr[[2]]
descending <- !descending
Expand All @@ -90,4 +95,4 @@ find_and_remove_desc <- function(quosure) {
desc = descending
)
)
}
}
7 changes: 7 additions & 0 deletions r/tests/testthat/test-dplyr-arrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,11 @@ test_that("arrange() with bad inputs", {
"not found",
fixed = TRUE
)
expect_error(
tbl %>%
Table$create() %>%
arrange(desc(int, chr)),
"expects only one argument",
fixed = TRUE
)
})

0 comments on commit dedcbc0

Please sign in to comment.