-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rewrite `nth()`, `first()`, and `last()` using vctrs * NEWS bullet * Switch to a `vec_slice2()`-like behavior Because using `vec_slice()` breaks too many revdeps that use these functions on lists and expect to get list elements back * NEWS bullet tweaks * Apply suggestions from code review * Typo
- Loading branch information
1 parent
eaac641
commit 1b52611
Showing
6 changed files
with
379 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,56 @@ | ||
# nth() gives meaningful error message (#5466) | ||
# `default` must be size 1 (when not used with lists) | ||
|
||
Code | ||
(expect_error(nth(1:10, "x"))) | ||
Output | ||
<error/rlang_error> | ||
nth(1L, n = 2L, default = 1:2) | ||
Condition | ||
Error in `nth()`: | ||
! `n` must be a single integer. | ||
! `default` must have size 1, not size 2. | ||
|
||
# `default` is cast to the type of `x` (when not used with lists) | ||
|
||
Code | ||
nth("x", 2, default = 2) | ||
Condition | ||
Error in `nth()`: | ||
! Can't convert `default` <double> to match type of `x` <character>. | ||
|
||
# `n` is validated (#5466) | ||
|
||
Code | ||
nth(1:10, n = "x") | ||
Condition | ||
Error in `nth()`: | ||
! Can't convert `n` <character> to <integer>. | ||
|
||
--- | ||
|
||
Code | ||
nth(1:10, n = 1:2) | ||
Condition | ||
Error in `nth()`: | ||
! `n` must have size 1, not size 2. | ||
|
||
# `x` must be a vector | ||
|
||
Code | ||
nth(environment(), 1L) | ||
Condition | ||
Error in `vec_size()`: | ||
! `x` must be a vector, not an environment. | ||
|
||
# `order_by` must be the same size as `x` | ||
|
||
Code | ||
nth(1:5, n = 1L, order_by = 1:2) | ||
Condition | ||
Error in `nth()`: | ||
! `order_by` must have size 5, not size 2. | ||
|
||
--- | ||
|
||
Code | ||
nth(1:5, n = 6L, order_by = 1:2) | ||
Condition | ||
Error in `nth()`: | ||
! `order_by` must have size 5, not size 2. | ||
|
Oops, something went wrong.