vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

`vec_slice()` should probably propagate the names of logical NAs

Open lionel- opened this issue 3 years ago • 1 comments

Current behaviour:

x <- c(a = 1, b = 2, c = 3, d = 4)
vec_slice(x, c(TRUE, NA, FALSE, NA))
#>  a
#>  1 NA NA

I would have expected:

#>  a  b  d
#>  1 NA NA

In the integer and character cases, there is no correspondence between the vector and subscript elements, so the current behaviour is correct.

vec_slice(x, c(1, NA, 2))
#>  a     b
#>  1 NA  2

That might be a case where we'd want to use the subscript name instead of the vector name, if available, but probably not worth the added complexity.

lionel- avatar Aug 31 '22 09:08 lionel-

That's tough because the first thing we do in vec_slice() is call vec_as_location(), which forces us to lose the context of where the NA originated from

vctrs::vec_as_location(c(TRUE, NA, FALSE, NA), n = 4)
#> [1]  1 NA NA

Created on 2022-08-31 with reprex v2.0.2

DavisVaughan avatar Aug 31 '22 13:08 DavisVaughan