Skip to content

has_rownames() glitch #852

@romainfrancois

Description

@romainfrancois

I believe has_rownames() suffers from a problem in .row_names_info(type = 1):

df <- data.frame(x = 1:10)
df2 <- structure(df, .drop = FALSE)
df3 <- `attr<-`(df, ".drop", FALSE)

.row_names_info(df, type = 0)
#> [1]  NA -10
.row_names_info(df2, type = 0)
#> [1] NA 10
.row_names_info(df3, type = 0)
#> [1]  NA -10

.row_names_info(df, type = 1)
#> [1] -10
.row_names_info(df2, type = 1)
#> [1] 10
.row_names_info(df3, type = 1)
#> [1] -10

.row_names_info(df, type = 2)
#> [1] 10
.row_names_info(df2, type = 2)
#> [1] 10
.row_names_info(df3, type = 2)
#> [1] 10

Created on 2021-02-11 by the reprex package (v0.3.0)

Specifically:

.row_names_info(df2, type = 1)
#> [1] 10

In the end, I believe this is a bug in structure(), and I've added a fix to dplyr so that it does not use structure() in the problem from tidyverse/dplyr#5745 but I still believe has_rownames() could work around that quirk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions