`rows_update` Error: `x` key values are not unique

Viewed 1054

Is it possible to use rows_update with non-unique x values?

library(dplyr)

x = tibble(x = c(1,1,2), z = "x")
y = tibble(x = c(1,2), z = "y") 
   
rows_update(x, y)
#> Matching, by = "x"
#> Error: `x` key values are not unique.

Created on 2020-07-17 by the reprex package (v0.3.0)

1 Answers

The issue is that rows_update requires key variables to take unique values. If the constraint is to use rows_update without creating extra-columns, I would propose:

x %>% distinct() %>% 
rows_update(y, by = "x") %>% 
right_join(x %>% select(x), by = "x")
Related