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

Bug: join_type = "before" produces confusing results #2683

Open
bundfussr opened this issue Mar 12, 2025 · 0 comments
Open

Bug: join_type = "before" produces confusing results #2683

bundfussr opened this issue Mar 12, 2025 · 0 comments
Labels
bug Something isn't working programming

Comments

@bundfussr
Copy link
Collaborator

What happened?

If join_type = "before" is specified in derive_vars_joined() and dataset and dataset_add don't have the same observations, the result can be confusing.

Session Information

No response

Reproducible Example

library(tibble)
adbds <- tibble(subj = "1", day = c(15, 17, 20), val = c(-1, 0, 1))
derive_vars_joined(
  adbds,
  dataset_add = adbds %>% filter(val >= 0),
  by_vars = exprs(subj),
  order = exprs(day),
  new_vars = exprs(lastposval = val),
  join_type = "before",
  mode = "last"
)

produces

# A tibble: 3 × 4
  subj    day   val lastposval
  <chr> <dbl> <dbl>      <dbl>
1 1        15    -1         NA
2 1        17     0          0
3 1        20     1          1

instead of

# A tibble: 3 × 4
  subj    day   val lastposval
  <chr> <dbl> <dbl>      <dbl>
1 1        15    -1         NA
2 1        17     0         NA
3 1        20     1          0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working programming
Development

No branches or pull requests

1 participant