dplyr semi_join Error: `x` and `y` must share the same src, set `copy` = TRUE (may be slow)

dplyr semi_join Error: `x` and `y` must share the same src, set `copy` = TRUE (may be slow)

我正在使用 dplyr 1.0.6 和 R 4.1.0,我写了 2 个函数如下:

AllCustomersList <- loadAllCustomersData()

CouldJoinByNationalID <- matchCustomersByNationalCode(AllCustomersList = AllCustomersList)

loadAllCustomersData() returns 两个数据框的列表,然后 matchCustomersByNationalCode 尝试对这两个 data.frame 执行 semi_join,如下所示:

matchCustomersByNationalCode <- function(AllCustomersList) {
  
  FDCustomers <- AllCustomersList$FDCustomers
  Customers <- AllCustomersList$Customers
  
  semi_join(x = FDCustomers, y = Customers, by = c("NationalID" = "NationalCode"), na_matches = "never") %>% 
    pull(NationalID) %>% 
    return()
}

实际上,就命名而言,这只是 semi_join 的包装。但它通过一个错误说:

Error: x and y must share the same src, set copy = TRUE (may be slow).

Run rlang::last_error() to see where the error occurred.

Called from: signal_abort(cnd)

有人可以帮忙吗?

感谢 walter and Martin Gal 我尝试制作一个可重现的示例并且成功了!所以我检查了 data.frames 的 class,它说它们都是 data.frames。但是我在 match 函数中再次将它们转换为 data.frame 并且它起作用了!这对我来说仍然很奇怪,但问题已解决!