I'd like to split a data set in order to obtain a train and test set. The slice_sample function helps me to split by n or prop and take into account groups, which is great. Then, anti_join helps me to get the other half of the data, given the sliced data. However, anti_join removes all identical rows, such that if there are duplicates in the data, it might remove all of those, rather then only the sliced ones.
data_test <- iris %>% slice_sample(n = 40)
data_train <- iris %>% anti_join(data_test)
Is there a tidyverse way to fix this?