Skip to content

Error when adding a zero row tibble with add_row() #809

Description

@DavisVaughan

While this looks like a vctrs issue, I think it is actually a tibble issue

library(tidyverse)

t <- tibble(x=1,y=2)
tr <- tribble(~x, ~y,)

t %>% add_row(tr)
#> Error: Internal error in `vec_assign()`: `value` should have been recycled to fit `x`.

tr %>% add_row(t)
#> # A tibble: 1 x 2
#>       x     y
#>   <dbl> <dbl>
#> 1     1     2

add_row() has this line that manually overwrites the row names

tibble/R/add.R

Line 52 in b4eec19

attr(df, "row.names") <- .set_row_names(max(1L, nrow(df)))

vctrs uses this property to figure out the number of rows in the data frame, and with a 0-row data frame this line sets the number of rows to 1, which causes issues.

I think the purpose of this check is to ensure that add_row(df) adds a single row of missing values when the user hasn't provided any input, but there are other ways to get at that besides overwriting the row names attribute. I'll submit a PR with an alternative

Somewhat related commit 21541de

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions