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

vec_slice() errors in conjunction with data.table::data.table(), lubridate::period() and rbind() #1905

Open
Henning-Lenz opened this issue Dec 22, 2023 · 1 comment

Comments

@Henning-Lenz
Copy link

Henning-Lenz commented Dec 22, 2023

vctrs package (version 0.6.5 on R 4.3.2) told me to report, so I obey. MWE:

measurements <- data.table::data.table(
  "id" = seq(1, 10),
  "someperiod" = rep(lubridate::period(5), 10)
)

allmeasurements <- rbind(measurements, measurements)

test <- dplyr::arrange(allmeasurements, id)
#> Error in `vec_slice()`:
#> ! Column `someperiod` (size 10) must match the data frame (size 20).
#> ℹ In file 'slice.c' at line 188.
#> ℹ This is an internal error that was detected in the vctrs package.
#>   Please report it at <https://github.com/r-lib/vctrs/issues> with a reprex (<https://tidyverse.org/help/>) and the full backtrace.
#> Backtrace:
#>      ▆
#>   1. ├─dplyr::arrange(allmeasurements, id)
#>   2. ├─dplyr:::arrange.data.frame(allmeasurements, id)
#>   3. │ ├─dplyr::dplyr_row_slice(.data, loc)
#>   4. │ └─dplyr:::dplyr_row_slice.data.frame(.data, loc)
#>   5. │   ├─dplyr::dplyr_reconstruct(vec_slice(data, i), data)
#>   6. │   │ └─dplyr:::dplyr_new_data_frame(data)
#>   7. │   │   ├─row.names %||% .row_names_info(x, type = 0L)
#>   8. │   │   └─base::.row_names_info(x, type = 0L)
#>   9. │   └─vctrs::vec_slice(data, i)
#>  10. └─rlang:::stop_internal_c_lib(...)
#>  11.   └─rlang::abort(message, call = call, .internal = TRUE, .frame = frame)

Created on 2023-12-22 with reprex v2.0.2

While constructing the MWE I found, that it is crucial to

  • use data.table::data.table() as tibble::tibble() and data.frame() work fine
  • use some lubridate::period() because plain integers work and lubridate::duration() work, too

Converting to tibble or data.frame before (but not after) using rbind() produces no error.

So it needs a very special combination of objects to be problematic and perhaps therefore it's originally caused by one of the other packages.

@eutwt
Copy link

eutwt commented Dec 27, 2023

Looks like rbind.data.table doesn't combine Period columns the same way rbind.data.frame / the Period method of c would, combining the vectors in the object's attributes. This prevents you from subsetting with [.data.table too, e.g. allmeasurements[1,] errors.

data.table issue:
Rdatatable/data.table#1454

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants