From df9a94183ed7f54736a603acf87d84c0fcf54fb0 Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Thu, 20 Oct 2022 12:16:12 +0200 Subject: [PATCH] Use "can't" phrasing in headers of subscript errors --- R/subscript.R | 14 ++- tests/testthat/_snaps/error-call.md | 10 +- tests/testthat/_snaps/slice-assign.md | 8 +- tests/testthat/_snaps/slice-chop.md | 8 +- tests/testthat/_snaps/slice.md | 10 +- tests/testthat/_snaps/subscript-loc.md | 154 ++++++++++++------------- tests/testthat/_snaps/subscript.md | 38 +++--- 7 files changed, 125 insertions(+), 117 deletions(-) diff --git a/R/subscript.R b/R/subscript.R index 7b87c0ba0..e524a2f58 100644 --- a/R/subscript.R +++ b/R/subscript.R @@ -175,12 +175,20 @@ new_error_subscript_type <- function(i, #' @export cnd_header.vctrs_error_subscript_type <- function(cnd) { - action <- cnd_subscript_action(cnd) + arg <- cnd[["subscript_arg"]] + if (is_subscript_arg(arg)) { + with <- glue::glue(" with {format_subscript_arg(arg)}") + } else { + with <- "" + } + + action <- cnd_subscript_action(cnd, assign_to = FALSE) elt <- cnd_subscript_element(cnd) + if (cnd_subscript_scalar(cnd)) { - glue::glue("Must {action} {elt[[1]]} with a single valid subscript.") + glue::glue("Can't {action} {elt[[1]]}{with}.") } else { - glue::glue("Must {action} {elt[[2]]} with a valid subscript vector.") + glue::glue("Can't {action} {elt[[2]]}{with}.") } } #' @export diff --git a/tests/testthat/_snaps/error-call.md b/tests/testthat/_snaps/error-call.md index eb9c1af3b..9fa9ddc08 100644 --- a/tests/testthat/_snaps/error-call.md +++ b/tests/testthat/_snaps/error-call.md @@ -218,7 +218,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `my_arg`. x Can't convert from `my_arg` to due to loss of precision. --- @@ -228,7 +228,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Can't convert from to due to loss of precision. --- @@ -238,7 +238,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `my_arg`. x `my_arg` must be logical, numeric, or character, not an empty list. --- @@ -258,7 +258,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain missing values. x It has a missing value at location 1. @@ -326,7 +326,7 @@ Output Error in `vec_slice()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `i`. x `i` must be logical, numeric, or character, not an environment. # list_sizes() reports error context diff --git a/tests/testthat/_snaps/slice-assign.md b/tests/testthat/_snaps/slice-assign.md index 5d1d2b540..93eebb30e 100644 --- a/tests/testthat/_snaps/slice-assign.md +++ b/tests/testthat/_snaps/slice-assign.md @@ -16,7 +16,7 @@ Output Error: - ! Must assign to elements with a valid subscript vector. + ! Can't assign elements. x Logical subscript must be size 1 or 2, not 3. --- @@ -27,7 +27,7 @@ Output Error: - ! Must assign to elements with a valid subscript vector. + ! Can't assign elements. x Logical subscript must be size 1 or 32, not 2. # must assign existing elements @@ -72,7 +72,7 @@ Output Error: - ! Must assign to elements with a valid subscript vector. + ! Can't assign elements. x Negative and positive locations can't be mixed. i Subscript has a positive value at location 2. Code @@ -81,7 +81,7 @@ Output Error: - ! Must assign to elements with a valid subscript vector. + ! Can't assign elements. x Negative locations can't have missing values. i Subscript has a missing value at location 2. diff --git a/tests/testthat/_snaps/slice-chop.md b/tests/testthat/_snaps/slice-chop.md index 97d2cd8d1..f79e057c2 100644 --- a/tests/testthat/_snaps/slice-chop.md +++ b/tests/testthat/_snaps/slice-chop.md @@ -158,7 +158,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain `0` values. i It has a `0` value at location 1. Code @@ -167,7 +167,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain negative locations. # list_unchop() fails with complex foreign S3 classes @@ -298,7 +298,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript must be numeric, not the string "x". Code (expect_error(list_unchop(list(1), indices = list(foobar(1L))), class = "vctrs_error_subscript_type") @@ -306,7 +306,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript must be numeric, not a object. # can ignore names in `list_unchop()` by providing a `zap()` name-spec (#232) diff --git a/tests/testthat/_snaps/slice.md b/tests/testthat/_snaps/slice.md index 62fed97f0..ef493a9a2 100644 --- a/tests/testthat/_snaps/slice.md +++ b/tests/testthat/_snaps/slice.md @@ -5,7 +5,7 @@ Output Error in `vec_slice()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `i`. x `i` must be logical, numeric, or character, not a object. Code (expect_error(vec_slice(1:3, matrix(TRUE, nrow = 1)), class = "vctrs_error_subscript_type") @@ -13,7 +13,7 @@ Output Error in `vec_slice()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `i`. x Subscript `i` must be a simple vector, not a matrix. # can't index beyond the end of a vector @@ -42,7 +42,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `2^31`. x Can't convert from `2^31` to due to loss of precision. # Unnamed vector with character subscript is caught @@ -59,7 +59,7 @@ vec_slice(1:3, -c(1L, NA)) Condition Error in `vec_slice()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `i`. x Negative locations can't have missing values. i Subscript `i` has a missing value at location 2. @@ -69,7 +69,7 @@ vec_slice(1:3, c(-1L, 1L)) Condition Error in `vec_slice()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `i`. x Negative and positive locations can't be mixed. i Subscript `i` has a positive value at location 2. diff --git a/tests/testthat/_snaps/subscript-loc.md b/tests/testthat/_snaps/subscript-loc.md index 641f0af34..b60ade633 100644 --- a/tests/testthat/_snaps/subscript-loc.md +++ b/tests/testthat/_snaps/subscript-loc.md @@ -6,7 +6,7 @@ Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `TRUE`. x `TRUE` must be numeric or character, not `TRUE`. Code (expect_error(vec_as_location2(mtcars, 10L), class = "vctrs_error_subscript_type") @@ -14,7 +14,7 @@ Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `mtcars`. x `mtcars` must be numeric or character, not a object. Code (expect_error(vec_as_location2(env(), 10L), class = "vctrs_error_subscript_type") @@ -22,7 +22,7 @@ Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `env()`. x `env()` must be numeric or character, not an environment. Code (expect_error(vec_as_location2(foobar(), 10L), class = "vctrs_error_subscript_type") @@ -30,21 +30,21 @@ Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foobar()`. x `foobar()` must be numeric or character, not a object. Code (expect_error(vec_as_location2(2.5, 10L), class = "vctrs_error_subscript_type")) Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `2.5`. x Can't convert from `2.5` to due to loss of precision. Code (expect_error(vec_as_location2(Inf, 10L), class = "vctrs_error_subscript_type")) Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `Inf`. x Can't convert from `Inf` to due to loss of precision. Code (expect_error(vec_as_location2(-Inf, 10L), class = "vctrs_error_subscript_type") @@ -52,7 +52,7 @@ Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `-Inf`. x Can't convert from `-Inf` to due to loss of precision. Code # Idem with custom `arg` @@ -61,7 +61,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x `foo` must be numeric or character, not a object. Code (expect_error(vec_as_location2(2.5, 3L, arg = "foo", call = call("my_function")), @@ -69,7 +69,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x Can't convert from `foo` to due to loss of precision. Code (expect_error(with_tibble_rows(vec_as_location2(TRUE)), class = "vctrs_error_subscript_type") @@ -77,7 +77,7 @@ Output Error: - ! Must remove row with a single valid subscript. + ! Can't remove row with `foo(bar)`. x `foo(bar)` must be numeric or character, not `TRUE`. # vec_as_location() requires integer, character, or logical inputs @@ -88,7 +88,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `mtcars`. x `mtcars` must be logical, numeric, or character, not a object. Code (expect_error(vec_as_location(env(), 10L), class = "vctrs_error_subscript_type") @@ -96,7 +96,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `env()`. x `env()` must be logical, numeric, or character, not an environment. Code (expect_error(vec_as_location(foobar(), 10L), class = "vctrs_error_subscript_type") @@ -104,14 +104,14 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `foobar()`. x `foobar()` must be logical, numeric, or character, not a object. Code (expect_error(vec_as_location(2.5, 10L), class = "vctrs_error_subscript_type")) Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `2.5`. x Can't convert from `2.5` to due to loss of precision. Code (expect_error(vec_as_location(list(), 10L), class = "vctrs_error_subscript_type") @@ -119,7 +119,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `list()`. x `list()` must be logical, numeric, or character, not an empty list. Code (expect_error(vec_as_location(function() NULL, 10L), class = "vctrs_error_subscript_type") @@ -127,7 +127,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `function() NULL`. x `function() NULL` must be logical, numeric, or character, not a function. Code (expect_error(vec_as_location(Sys.Date(), 3L), class = "vctrs_error_subscript_type") @@ -135,7 +135,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `Sys.Date()`. x `Sys.Date()` must be logical, numeric, or character, not a object. Code # Idem with custom `arg` @@ -144,7 +144,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `foo`. x `foo` must be logical, numeric, or character, not an environment. Code (expect_error(vec_as_location(foobar(), 10L, arg = "foo", call = call( @@ -152,7 +152,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `foo`. x `foo` must be logical, numeric, or character, not a object. Code (expect_error(vec_as_location(2.5, 3L, arg = "foo", call = call("my_function")), @@ -160,7 +160,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `foo`. x Can't convert from `foo` to due to loss of precision. # vec_as_location() and variants check for OOB elements (#1605) @@ -223,7 +223,7 @@ Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `1:2`. x Subscript `1:2` must be size 1, not 2. Code (expect_error(vec_as_location2(c("foo", "bar"), 2L, c("foo", "bar")), class = "vctrs_error_subscript_type") @@ -231,7 +231,7 @@ Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `c("foo", "bar")`. x Subscript `c("foo", "bar")` must be size 1, not 2. Code # Idem with custom `arg` @@ -240,7 +240,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x Subscript `foo` must be size 1, not 2. Code (expect_error(vec_as_location2(mtcars, 10L, arg = "foo", call = call( @@ -248,7 +248,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x `foo` must be numeric or character, not a object. Code (expect_error(vec_as_location2(1:2, 2L, arg = "foo", call = call("my_function")), @@ -256,7 +256,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x Subscript `foo` must be size 1, not 2. # vec_as_location2() requires positive integers @@ -266,14 +266,14 @@ Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `0`. x Subscript `0` must be a positive location, not 0. Code (expect_error(vec_as_location2(-1, 2L), class = "vctrs_error_subscript_type")) Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `-1`. x Subscript `-1` must be a positive location, not -1. Code # Idem with custom `arg` @@ -282,7 +282,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x Subscript `foo` must be a positive location, not 0. # vec_as_location2() fails with NA @@ -293,7 +293,7 @@ Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `na_int`. x Subscript `na_int` must be a location, not an integer `NA`. Code (expect_error(vec_as_location2(na_chr, 1L, names = "foo"), class = "vctrs_error_subscript_type") @@ -301,7 +301,7 @@ Output Error: - ! Must extract element with a single valid subscript. + ! Can't extract element with `na_chr`. x Subscript `na_chr` must be a location, not a character `NA`. Code # Idem with custom `arg` @@ -310,7 +310,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x Subscript `foo` must be a location, not an integer `NA`. # num_as_location() optionally forbids negative indices @@ -321,7 +321,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `dbl(1, -1)`. x Subscript `dbl(1, -1)` can't contain negative locations. # num_as_location() optionally forbids zero indices @@ -332,7 +332,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `0L`. x Subscript `0L` can't contain `0` values. i It has a `0` value at location 1. Code @@ -341,7 +341,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `c(0, 0, 0, 0, 0, 0)`. x Subscript `c(0, 0, 0, 0, 0, 0)` can't contain `0` values. i It has 6 `0` values at locations 1, 2, 3, 4, 5, etc. @@ -353,7 +353,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `-c(1L, NA)`. x Negative locations can't have missing values. i Subscript `-c(1L, NA)` has a missing value at location 2. Code @@ -362,7 +362,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `-c(1L, rep(NA, 10))`. x Negative locations can't have missing values. i Subscript `-c(1L, rep(NA, 10))` has 10 missing values at locations 2, 3, 4, 5, 6, etc. @@ -374,7 +374,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `c(-1L, 1L)`. x Negative and positive locations can't be mixed. i Subscript `c(-1L, 1L)` has a positive value at location 2. Code @@ -383,7 +383,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `c(-1L, rep(1L, 10))`. x Negative and positive locations can't be mixed. i Subscript `c(-1L, rep(1L, 10))` has 10 positive values at locations 2, 3, 4, 5, 6, etc. @@ -395,7 +395,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `c(TRUE, FALSE)`. x Logical subscript `c(TRUE, FALSE)` must be size 1 or 3, not 2. # character subscripts require named vectors @@ -481,7 +481,7 @@ num_as_location(c(0, -1), n = 2L, negative = "invert", zero = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `c(0, -1)`. x Subscript `c(0, -1)` can't contain `0` values. i It has a `0` value at location 1. @@ -491,7 +491,7 @@ num_as_location(c(-1, 0), n = 2L, negative = "invert", zero = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `c(-1, 0)`. x Subscript `c(-1, 0)` can't contain `0` values. i It has a `0` value at location 2. @@ -564,7 +564,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain missing values. x It has a missing value at location 2. Code @@ -573,7 +573,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain missing values. x It has missing values at locations 2 and 4. Code @@ -582,7 +582,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x Subscript `foo(bar)` can't contain missing values. x It has missing values at locations 2 and 4. Code @@ -591,7 +591,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x Subscript `foo(bar)` can't contain missing values. x It has a missing value at location 1. Code @@ -600,7 +600,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x Subscript `foo(bar)` can't contain missing values. x It has a missing value at location 1. Code @@ -609,7 +609,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x Subscript `foo(bar)` can't contain missing values. x It has a missing value at location 2. Code @@ -618,7 +618,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x Subscript `foo(bar)` can't contain missing values. x It has a missing value at location 1. @@ -628,7 +628,7 @@ vec_as_location(x, n = 4L, missing = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain missing values. x It has missing values at locations 2 and 4. @@ -638,7 +638,7 @@ vec_as_location(x, n = 2L, missing = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain missing values. x It has a missing value at location 1. @@ -648,7 +648,7 @@ vec_as_location(x, n = 2L, names = names, missing = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain missing values. x It has missing values at locations 1 and 3. @@ -658,7 +658,7 @@ vec_as_location(x, n = 4L, missing = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain missing values. x It has missing values at locations 1 and 3. @@ -668,7 +668,7 @@ num_as_location(x, n = 4L, missing = "propagate", negative = "invert") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `x`. x Negative locations can't have missing values. i Subscript `x` has 2 missing values at locations 2 and 3. @@ -678,7 +678,7 @@ num_as_location(x, n = 4L, missing = "error", negative = "invert") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `x`. x Negative locations can't have missing values. i Subscript `x` has 2 missing values at locations 2 and 3. @@ -688,7 +688,7 @@ vec_as_location("", n = 2L, names = names) Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain the empty string. x It has an empty string at location 1. @@ -698,7 +698,7 @@ vec_as_location(c("", "y", ""), n = 2L, names = names) Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript can't contain the empty string. x It has an empty string at locations 1 and 3. @@ -711,7 +711,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `foo`. x Subscript `foo` can't contain negative locations. Code (expect_error(num_as_location2(-1, 2, negative = "error", arg = "foo", call = call( @@ -719,7 +719,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x Subscript `foo` must be a positive location, not -1. Code (expect_error(vec_as_location2(0, 2, arg = "foo", call = call("my_function")), @@ -727,7 +727,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x Subscript `foo` must be a positive location, not 0. Code (expect_error(vec_as_location2(na_dbl, 2, arg = "foo", call = call( @@ -735,7 +735,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x Subscript `foo` must be a location, not an integer `NA`. Code (expect_error(vec_as_location2(c(1, 2), 2, arg = "foo", call = call( @@ -743,7 +743,7 @@ Output Error in `my_function()`: - ! Must extract element with a single valid subscript. + ! Can't extract element with `foo`. x Subscript `foo` must be size 1, not 2. Code (expect_error(vec_as_location(c(TRUE, FALSE), 3, arg = "foo", call = call( @@ -751,7 +751,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `foo`. x Logical subscript `foo` must be size 1 or 3, not 2. Code (expect_error(vec_as_location(c(-1, NA), 3, arg = "foo", call = call( @@ -759,7 +759,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `foo`. x Negative locations can't have missing values. i Subscript `foo` has a missing value at location 2. Code @@ -768,7 +768,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `foo`. x Negative and positive locations can't be mixed. i Subscript `foo` has a positive value at location 2. Code @@ -786,7 +786,7 @@ Output Error in `my_function()`: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `foo`. x Subscript `foo` can't contain `0` values. i It has a `0` value at location 1. Code @@ -796,7 +796,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x Subscript `foo(bar)` can't contain negative locations. Code (expect_error(with_tibble_cols(num_as_location2(-1, 2, negative = "error")), @@ -804,7 +804,7 @@ Output Error: - ! Must rename column with a single valid subscript. + ! Can't rename column with `foo(bar)`. x Subscript `foo(bar)` must be a positive location, not -1. Code (expect_error(with_tibble_cols(vec_as_location2(0, 2)), class = "vctrs_error_subscript_type") @@ -812,7 +812,7 @@ Output Error: - ! Must rename column with a single valid subscript. + ! Can't rename column with `foo(bar)`. x Subscript `foo(bar)` must be a positive location, not 0. Code (expect_error(with_tibble_cols(vec_as_location2(na_dbl, 2)), class = "vctrs_error_subscript_type") @@ -820,7 +820,7 @@ Output Error: - ! Must rename column with a single valid subscript. + ! Can't rename column with `foo(bar)`. x Subscript `foo(bar)` must be a location, not an integer `NA`. Code (expect_error(with_tibble_cols(vec_as_location2(c(1, 2), 2)), class = "vctrs_error_subscript_type") @@ -828,7 +828,7 @@ Output Error: - ! Must rename column with a single valid subscript. + ! Can't rename column with `foo(bar)`. x Subscript `foo(bar)` must be size 1, not 2. Code (expect_error(with_tibble_cols(vec_as_location(c(TRUE, FALSE), 3)), class = "vctrs_error_subscript_size") @@ -836,7 +836,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x Logical subscript `foo(bar)` must be size 1 or 3, not 2. Code (expect_error(with_tibble_cols(vec_as_location(c(-1, NA), 3)), class = "vctrs_error_subscript_type") @@ -844,7 +844,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x Negative locations can't have missing values. i Subscript `foo(bar)` has a missing value at location 2. Code @@ -853,7 +853,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x Negative and positive locations can't be mixed. i Subscript `foo(bar)` has a positive value at location 2. Code @@ -871,7 +871,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x Subscript `foo(bar)` can't contain `0` values. i It has a `0` value at location 1. @@ -1020,7 +1020,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `matrix(TRUE, nrow = 1)`. x Subscript `matrix(TRUE, nrow = 1)` must be a simple vector, not a matrix. Code (expect_error(vec_as_location(array(TRUE, dim = c(1, 1, 1)), 3L), class = "vctrs_error_subscript_type") @@ -1028,7 +1028,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements with `array(TRUE, dim = c(1, 1, 1))`. x Subscript `array(TRUE, dim = c(1, 1, 1))` must be a simple vector, not an array. Code (expect_error(with_tibble_rows(vec_as_location(matrix(TRUE, nrow = 1), 3L)), @@ -1036,7 +1036,7 @@ Output Error: - ! Must remove rows with a valid subscript vector. + ! Can't remove rows with `foo(bar)`. x Subscript `foo(bar)` must be a simple vector, not a matrix. # vec_as_location() UI diff --git a/tests/testthat/_snaps/subscript.md b/tests/testthat/_snaps/subscript.md index 1e0a13fa4..43aa2ff5c 100644 --- a/tests/testthat/_snaps/subscript.md +++ b/tests/testthat/_snaps/subscript.md @@ -6,7 +6,7 @@ Output Error: - ! Must rename columns with a valid subscript vector. + ! Can't rename columns with `foo(bar)`. x `foo(bar)` must be logical, numeric, or character, not an environment. --- @@ -17,7 +17,7 @@ Output Error: - ! Must extract tables with a valid subscript vector. + ! Can't extract tables with `foo(bar)`. x `foo(bar)` must be logical, numeric, or character, not an environment. # vec_as_subscript() checks dimensionality @@ -28,7 +28,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript must be a simple vector, not a matrix. Code (expect_error(vec_as_subscript(array(TRUE, dim = c(1, 1, 1))), class = "vctrs_error_subscript_type") @@ -36,7 +36,7 @@ Output Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript must be a simple vector, not an array. Code (expect_error(with_tibble_rows(vec_as_subscript(matrix(TRUE, nrow = 1))), @@ -44,7 +44,7 @@ Output Error: - ! Must remove rows with a valid subscript vector. + ! Can't remove rows with `foo(bar)`. x Subscript `foo(bar)` must be a simple vector, not a matrix. # vec_as_subscript() forbids subscript types @@ -53,7 +53,7 @@ vec_as_subscript(1L, logical = "error", numeric = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript must be character, not the number 1. --- @@ -62,7 +62,7 @@ vec_as_subscript("foo", logical = "error", character = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript must be numeric, not the string "foo". --- @@ -71,7 +71,7 @@ vec_as_subscript(TRUE, logical = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript must be numeric or character, not `TRUE`. --- @@ -80,7 +80,7 @@ vec_as_subscript("foo", character = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript must be logical or numeric, not the string "foo". --- @@ -89,7 +89,7 @@ vec_as_subscript(NULL, numeric = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript must be logical or character, not `NULL`. --- @@ -98,7 +98,7 @@ vec_as_subscript(quote(foo), character = "error") Condition Error: - ! Must subset elements with a valid subscript vector. + ! Can't subset elements. x Subscript must be logical or numeric, not a symbol. # vec_as_subscript2() forbids subscript types @@ -107,7 +107,7 @@ vec_as_subscript2(1L, numeric = "error") Condition Error: - ! Must extract element with a single valid subscript. + ! Can't extract element. x Subscript must be character, not the number 1. --- @@ -116,7 +116,7 @@ vec_as_subscript2("foo", character = "error") Condition Error: - ! Must extract element with a single valid subscript. + ! Can't extract element. x Subscript must be numeric, not the string "foo". --- @@ -125,7 +125,7 @@ vec_as_subscript2(TRUE) Condition Error: - ! Must extract element with a single valid subscript. + ! Can't extract element. x Subscript must be numeric or character, not `TRUE`. # vec_as_subscript2() retains the call when throwing vec_as_subscript() errors (#1605) @@ -134,7 +134,7 @@ vec_as_subscript2(1L, numeric = "error", call = call("foo")) Condition Error in `foo()`: - ! Must extract element with a single valid subscript. + ! Can't extract element. x Subscript must be character, not the number 1. --- @@ -143,7 +143,7 @@ vec_as_subscript2(1.5, call = call("foo")) Condition Error in `foo()`: - ! Must extract element with a single valid subscript. + ! Can't extract element. x Can't convert from to due to loss of precision. # vec_as_subscript2() retains the call when erroring on logical input (#1605) @@ -152,7 +152,7 @@ vec_as_subscript2(TRUE, call = call("foo")) Condition Error in `foo()`: - ! Must extract element with a single valid subscript. + ! Can't extract element. x Subscript must be numeric or character, not `TRUE`. # `logical = 'cast'` is deprecated @@ -169,7 +169,7 @@ vec_as_subscript2(TRUE, logical = "error") Condition Error: - ! Must extract element with a single valid subscript. + ! Can't extract element. x Subscript must be numeric or character, not `TRUE`. # lossy cast errors for scalar subscripts work (#1606) @@ -178,6 +178,6 @@ vec_as_subscript2(1.5) Condition Error: - ! Must extract element with a single valid subscript. + ! Can't extract element. x Can't convert from to due to loss of precision.