Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DavisVaughan opened this issue Sep 1, 2020 · 1 comment · Fixed by #810
Closed

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

DavisVaughan opened this issue Sep 1, 2020 · 1 comment · Fixed by #810

Comments

@DavisVaughan
Copy link
Member

DavisVaughan commented Sep 1, 2020

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

krlmlr added a commit that referenced this issue Sep 2, 2020
- `add_row(df)` adds an empty row again (#809, @DavisVaughan).
krlmlr added a commit that referenced this issue Feb 25, 2021
tibble 3.0.4

- Establish compatibility with upcoming pillar 1.5.0 (#818).

- `tbl_sum()` shows "data frame" instead of "tibble" for objects inheriting from `"tbl"` but not `"tbl_df"` (#818).

- Export `format.tbl()` and `print.tbl()` only if pillar doesn't (#816).

- Use `vctrs::num_as_location()` internally for subset assignment of rows and columns for better error messages (#746).

- Adapt tests to the development version of testthat.

- Fix documentation link to `base::Extract`.

- `add_row(df)` adds an empty row again (#809, @DavisVaughan).
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2021

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant