Skip to content

Commit 420c834

Browse files
committed
Use "can't" phrasing in unknown named location errors
1 parent a6be73d commit 420c834

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

R/subscript-loc.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,16 @@ cnd_body_vctrs_error_subscript_oob_location <- function(cnd, ...) {
541541
))
542542
}
543543
cnd_body_vctrs_error_subscript_oob_name <- function(cnd, ...) {
544-
elt <- cnd_subscript_element(cnd, capital = TRUE)
544+
elt <- cnd_subscript_element(cnd, capital = FALSE)
545+
elt_cap <- cnd_subscript_element(cnd, capital = TRUE)
545546
oob <- cnd$i[!cnd$i %in% cnd$names]
546547
oob_enum <- enumerate(glue::backtick(oob))
547548

548549
format_error_bullets(c(
549550
x = glue::glue(ngettext(
550551
length(oob),
551-
"{elt[[1]]} {oob_enum} doesn't exist.",
552-
"{elt[[2]]} {oob_enum} don't exist."
552+
"Can't find {elt[[1]]} {oob_enum}.",
553+
"Can't find {elt[[2]]} {oob_enum}.",
553554
))
554555
))
555556
}

tests/testthat/_snaps/conditions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@
2323
<error/vctrs_error_subscript_oob>
2424
Error in `vec_slice()`:
2525
! Can't subset elements.
26-
x Element `foo` doesn't exist.
26+
x Can't find element `foo`.
2727
Code
2828
(expect_error(with_subscript_data(vec_slice(set_names(letters), "foo"), quote(
2929
foo)), class = "vctrs_error_subscript_oob"))
3030
Output
3131
<error/vctrs_error_subscript_oob>
3232
Error in `vec_slice()`:
3333
! Can't subset elements with `foo`.
34-
x Element `foo` doesn't exist.
34+
x Can't find element `foo`.
3535
Code
3636
(expect_error(with_subscript_data(vec_slice(set_names(letters), "foo"), quote(
3737
foo(bar))), class = "vctrs_error_subscript_oob"))
3838
Output
3939
<error/vctrs_error_subscript_oob>
4040
Error in `vec_slice()`:
4141
! Can't subset elements with `foo(bar)`.
42-
x Element `foo` doesn't exist.
42+
x Can't find element `foo`.
4343

4444
# scalar type errors are informative
4545

tests/testthat/_snaps/slice-assign.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<error/vctrs_error_subscript_oob>
6363
Error:
6464
! Can't assign elements.
65-
x Element `foo` doesn't exist.
65+
x Can't find element `foo`.
6666

6767
# must assign with proper negative locations
6868

tests/testthat/_snaps/slice.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
Condition
8181
Error in `vec_slice()`:
8282
! Can't subset elements with `i`.
83-
x Element `foo` doesn't exist.
83+
x Can't find element `foo`.
8484

8585
---
8686

@@ -111,7 +111,7 @@
111111
Condition
112112
Error in `vec_slice()`:
113113
! Can't subset elements with `i`.
114-
x Elements `foo` and `bar` don't exist.
114+
x Can't find elements `foo` and `bar`.
115115

116116
---
117117

@@ -120,7 +120,7 @@
120120
Condition
121121
Error in `vec_slice()`:
122122
! Can't subset elements with `i`.
123-
x Elements `A`, `B`, `C`, `D`, `E`, etc. don't exist.
123+
x Can't find elements `A`, `B`, `C`, `D`, `E`, etc..
124124

125125
# vec_init() validates `n`
126126

tests/testthat/_snaps/subscript-loc.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,23 @@
198198
<error/vctrs_error_subscript_oob>
199199
Error:
200200
! Can't subset elements with `"foo"`.
201-
x Element `foo` doesn't exist.
201+
x Can't find element `foo`.
202202
Code
203203
(expect_error(vec_as_location2("foo", 1L, names = "bar"), class = "vctrs_error_subscript_oob")
204204
)
205205
Output
206206
<error/vctrs_error_subscript_oob>
207207
Error:
208208
! Can't extract element with `"foo"`.
209-
x Element `foo` doesn't exist.
209+
x Can't find element `foo`.
210210
Code
211211
(expect_error(vec_as_location2("foo", 1L, names = "bar", call = call("baz")),
212212
class = "vctrs_error_subscript_oob"))
213213
Output
214214
<error/vctrs_error_subscript_oob>
215215
Error in `baz()`:
216216
! Can't extract element with `"foo"`.
217-
x Element `foo` doesn't exist.
217+
x Can't find element `foo`.
218218

219219
# vec_as_location2() requires length 1 inputs
220220

@@ -897,7 +897,7 @@
897897
<error/vctrs_error_subscript_oob>
898898
Error in `vec_slice()`:
899899
! Can't subset elements with `i`.
900-
x Element `foo` doesn't exist.
900+
x Can't find element `foo`.
901901
Code
902902
# With custom `arg`
903903
(expect_error(vec_as_location(30, length(letters), arg = "foo", call = call(
@@ -915,7 +915,7 @@
915915
<error/vctrs_error_subscript_oob>
916916
Error in `my_function()`:
917917
! Can't subset elements with `foo`.
918-
x Element `foo` doesn't exist.
918+
x Can't find element `foo`.
919919
Code
920920
# With tibble columns
921921
(expect_error(with_tibble_cols(vec_slice(set_names(letters), "foo")), class = "vctrs_error_subscript_oob")
@@ -924,7 +924,7 @@
924924
<error/vctrs_error_subscript_oob>
925925
Error in `vec_slice()`:
926926
! Can't rename columns with `foo(bar)`.
927-
x Column `foo` doesn't exist.
927+
x Can't find column `foo`.
928928
Code
929929
(expect_error(with_tibble_cols(vec_slice(set_names(letters), 30)), class = "vctrs_error_subscript_oob")
930930
)
@@ -951,7 +951,7 @@
951951
<error/vctrs_error_subscript_oob>
952952
Error in `vec_slice()`:
953953
! Can't remove rows with `foo(bar)`.
954-
x Rows `foo` and `bar` don't exist.
954+
x Can't find rows `foo` and `bar`.
955955
Code
956956
(expect_error(with_tibble_rows(vec_slice(set_names(letters), 1:30)), class = "vctrs_error_subscript_oob")
957957
)
@@ -980,7 +980,7 @@
980980
<error/vctrs_error_subscript_oob>
981981
Error in `vec_slice()`:
982982
! Can't select columns with `foo(bar)`.
983-
x Columns `foo` and `bar` don't exist.
983+
x Can't find columns `foo` and `bar`.
984984
Code
985985
(expect_error(with_tidyselect_select(vec_slice(set_names(letters), 30)), class = "vctrs_error_subscript_oob")
986986
)
@@ -1008,7 +1008,7 @@
10081008
<error/vctrs_error_subscript_oob>
10091009
Error in `vec_slice()`:
10101010
! Can't relocate columns with `foo(bar)`.
1011-
x Columns `foo` and `bar` don't exist.
1011+
x Can't find columns `foo` and `bar`.
10121012
Code
10131013
(expect_error(with_tidyselect_relocate(vec_slice(set_names(letters), 30)),
10141014
class = "vctrs_error_subscript_oob"))

0 commit comments

Comments
 (0)