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"