Missing deprecation warning when setting row names on tibble

Is deprecation of setting row names in a tibble mean doing this specifically using row.names(x) <- to do this? My guess is you should not set the row names in a tibble going forward no matter how you do it.

For example row.names in a tibble can be set using attr(x, which) without producing a warning.

The example below shows that row.names(x) produces a deprecation warning when used for a tibble but using attr(x,which) <- does not. It also shows that row.names(x) <- works fine, as expected, on a data.frame... that's the group that takes placebos :slight_smile:

It looks like going forward tibble's will not, in effect, have row names. ( https://github.com/tidyverse/tibble/issues/123 ) I guess to make them more like a database table and use columns to define a key.

This means that code that uses attr(x, which) to get around or just by luck avoid the deprecation warning could break or become unstable in the future, right?

# this sets the row names on a tibble
t1 <- tibble::tibble(1:4)
attr(t1, "row.names") <- 2:5
#> [1] "2" "3" "4" "5"

# however this produces a deprication warning
t2 <- tibble::tibble(1:4)
row.names(t2) <- 1:4
#> Warning: Setting row names on a tibble is deprecated.

# and row.names works fine on a data.frame

t3 <- data.frame(1:4)
row.names(t3) <- 2:5
#> [1] "2" "3" "4" "5"
1 Like

> library(tibble)
> t1 <- tibble::tibble(1:4)
> attr(t1, "row.names") <- 2:5
> row.names(t1)
[1] "2" "3" "4" "5"
> t2 <- tibble::tibble(1:4)
> row.names(t2) <- 1:4
Warning message:
Setting row names on a tibble is deprecated. 
> attributes(t1)
[1] "1:4"

[1] 2 3 4 5

[1] "tbl_df"     "tbl"        "data.frame"

> attributes(t2)
[1] "1:4"

[1] 1 2 3 4

[1] "tbl_df"     "tbl"        "data.frame"

Hasn't changed as of 2018-11-26. My guess is that they set the warning only with row.names in mind and overlooked attr

Not sure it's worth an issue until using attr on a tibble breaks something. But sure odd.