-
Couldn't load subscription status.
- Fork 135
Description
CRAN tibble
library(tibble)
tbl <- tibble(x = structure(c(1, 2), extra = "hi"))
tbl$x
#> [1] 1 2
#> attr(,"extra")
#> [1] "hi"
tbl[[1, 1]]
#> [1] 1Dev tibble
library(tibble)
tbl <- tibble(x = structure(c(1, 2), extra = "hi"))
tbl$x
#> [1] 1 2
#> attr(,"extra")
#> [1] "hi"
tbl[[1, 1]]
#> [1] 1
#> attr(,"extra")
#> [1] "hi"I think this is definitely not right. [[ should always strip attributes from atomic vectors.
The issue comes from using vec_slice() in [[.tbl_df here:
Line 122 in e9663b9
| vec_slice(x, i) |
The issue is that vec_slice() works more like [ which won't strip the attributes from the column. [[ would. The vctrs equivalent for [[ doesn't exist yet, but would be vec_get()
r-lib/vctrs#626
Note that base:::[[.data.frame uses [[ for the row extraction after selecting the column, which is why we previously had the correct behavior:
> base:::`[[.data.frame`
function (x, ..., exact = TRUE)
{
na <- nargs() - !missing(exact)
if (!all(names(sys.call()) %in% c("", "exact")))
warning("named arguments other than 'exact' are discouraged")
if (na < 3L)
(function(x, i, exact) if (is.matrix(i))
as.matrix(x)[[i]]
else .subset2(x, i, exact = exact))(x, ..., exact = exact)
else {
col <- .subset2(x, ..2, exact = exact)
i <- if (is.character(..1))
pmatch(..1, row.names(x), duplicates.ok = TRUE)
else ..1
col[[i, exact = exact]] # <- RIGHT HERE!
}
}vec_get() also behaves differently than vec_slice() with lists, so list column extraction is also different now.
CRAN tibble:
library(tibble)
tbl <- tibble(x = list(1, 2), y = 1:2)
tbl[[1, 1]]
#> [1] 1Dev tibble:
library(tibble)
tbl <- tibble(x = list(1, 2), y = 1:2)
tbl[[1, 1]]
#> [[1]]
#> [1] 1