vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

`vec_as_subscript2()` has a misleading error when given logical input with `logical = "cast"`

Open DavisVaughan opened this issue 1 year ago • 2 comments

Look at the first message:

Subscript has the wrong type logical.

It must be logical, numeric, or character.

library(vctrs)

vec_as_subscript2(TRUE, logical = "cast")
#> Error:
#> ! Must extract element with a single valid subscript.
#> ✖ Subscript has the wrong type `logical`.
#> ℹ It must be logical, numeric, or character.

vec_as_subscript2(TRUE, logical = "error")
#> Error:
#> ! Must extract element with a single valid subscript.
#> ✖ Subscript has the wrong type `logical`.
#> ℹ It must be numeric or character.

Also, why do we even expose a logical argument? Shouldn't it always be error? We internally error right before exiting if we have a logical argument.

DavisVaughan avatar Aug 11 '22 20:08 DavisVaughan

Also, why do we even expose a logical argument?

I don't remember. Maybe to follow base which coerces to integer?

letters[[TRUE]]
#> [1] "a"

lionel- avatar Sep 01 '22 11:09 lionel-

Since this never worked correctly, let's just keep it an error and remove the argument.

The only two usages on CRAN are in tidyselect and in tibble, and both packages set logical = "error".

lionel- avatar Sep 01 '22 11:09 lionel-