Skip to content

Make rows_insert() error if any columns in by do not exist in both x and y #6652

Description

@wurli

Fairly self-explanatory - rows_upsert() helpfully errors in such cases but the check seems to have been omitted in rows_insert():

library(dplyr, warn.conflicts = FALSE)

df1 <- tibble(x = 1:3, y = 2:4)
df2 <- tibble(x = 4:6)

# rows_insert() ignores "y"
rows_insert(df1, df2, by = c("x", "y"))
#> # A tibble: 6 × 2
#>       x     y
#>   <int> <int>
#> 1     1     2
#> 2     2     3
#> 3     3     4
#> 4     4    NA
#> 5     5    NA
#> 6     6    NA

# rows_update() helpfully errors
rows_update(df1, df2, by = c("x", "y"))
#> Error in `rows_update()`:
#> ! All columns specified through `by` must exist in `x` and `y`.
#> ℹ The following columns are missing from `y`: `y`.

#> Backtrace:
#>     ▆
#>  1. ├─dplyr::rows_update(df1, df2, by = c("x", "y"))
#>  2. └─dplyr:::rows_update.data.frame(df1, df2, by = c("x", "y"))
#>  3.   └─dplyr:::rows_select_key(y, by, "y", unique = TRUE)
#>  4.     └─rlang::abort(message, call = error_call)

Created on 2023-01-23 with reprex v2.0.2

Metadata

Metadata

Assignees

Labels

bugan unexpected problem or unintended behavior

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions