This code worked a couple days ago:
df<- tribble(
~ unique_id, ~event_type, ~ event_date,
'id_101', 'A_type_event', '2022-01-01',
'id_101', 'B_type_event', '2022-02-01',
'id_101', 'A_type_event', '2022-02-15',
'id_101', 'A_type_event', '2022-02-28',
'id_101', 'B_type_event', '2022-03-01',
'id_101', 'C_type_event', '2022-03-10',
'id_101', 'A_type_event', '2022-03-20',
'id_101', 'C_type_event', '2022-04-01'
)
left_join(
df %>% filter(event_type == "A_type_event"), # match A_type_event
df %>% filter(event_type == "C_type_event"), # with C_type_event
#join_by(event_date < event_date), # where A_type_event before C_type_event
join_by(unique_id, event_date < event_date), # ... and unique id matches
multiple = "first") # and just keep first match
Error code now is: Error in dplyr::common_by(): ! by must be a (named) character vector, list, or NULL for natural joins (not recommended in production code), not a <dplyr_join_by> object.
I tested the sample code on rdrr.io and another related stack overflow question on the same topic and they both return the same error.
Any idea how to fix the code?