SebKrantz / collapse

Advanced and Fast Data Transformation in R
https://sebkrantz.github.io/collapse/
Other
627 stars 33 forks source link

One-to-many full join w/ multiple flag throws error #562

Closed MattAFiedler closed 3 months ago

MattAFiedler commented 3 months ago

I am encountering an error with one-to-many full joins when the multiple flag is set. Here is a reproducible example:

library(tidyverse)
library(collapse)
join(tibble(id=1:2), tibble(id=rep(1:2,2)), how="full", multiple=TRUE)

The resulting error message is

Error in `[<-`:
! Assigned data `map(.subset(x, unname), vectbl_set_names, NULL)` must be compatible
  with existing data.
✖ Existing data has 2 rows.
✖ Assigned data has 4 rows.
ℹ Only vectors of size 1 are recycled.
Caused by error in `vectbl_recycle_rhs_rows()`:
! Can't recycle input of size 4 to size 2.
Run `rlang::last_trace()` to see where the error occurred.

Thank you very much for all of your work on collapse. It is hugely useful to me.

SebKrantz commented 3 months ago

Thanks @MattAFiedler. I've pushed out a fix to the master branch. Note that actually in this case the issue was that the "row.names" attribute was not modified. The output is however correct, thus even with the current version, you should be able to recover a valid result using

join(tibble(id=1:2), tibble(id=rep(1:2,2)), how="full", multiple=TRUE) |> qTBL()
MattAFiedler commented 3 months ago

Thank you!