Isabella Bingaman
Isabella Bingaman

Reputation: 11

Sets package in R causing dplyr functions to error (Error in FUN(X[[i]], ...) : only defined on a data frame with all numeric variables)

It appears that when I have the sets package installed in my global environment, it affects dplyr and janitor functions from executing correctly. For example, I cannot perform a basic mutate function when it is installed, getting the error "Error in FUN(X[[i]], ...) : only defined on a data frame with all numeric variables". To reproduce, see the code below:

EXAMPLE OF SETS ERROR

remove.packages(c("dplyr", "sets"))
install.packages("dplyr")
library(dplyr)

name <- c("Jon", "Bill", "Maria")
age <- c(23, 41, 32)

df <- data.frame(name, age)

data_2 <- df %>%
  dplyr::mutate(test = "test")

#looks good

## with sets
remove.packages(c("dplyr", "sets"))
install.packages("dplyr")
install.packages("sets")
library(dplyr)
library(sets)

name <- c("Jon", "Bill", "Maria")
age <- c(23, 41, 32)

df <- data.frame(name, age)

data_2 <- df %>%
  dplyr::mutate(test = "test")

Upvotes: 1

Views: 486

Answers (1)

Zaw
Zaw

Reputation: 1474

That's because sets package also has a pipe operator (%>%) conflicting with dplyr's pipe. One way to resolve this is to use conflicted package. Note the sequence of loading package: sets package is loaded first and conflict_prefer() call is right after loading dplyr.

library(conflicted)
library(sets)
library(dplyr)
conflict_prefer("%>%", "dplyr")

name <- c("Jon", "Bill", "Maria")
age <- c(23, 41, 32)
df <- data.frame(name, age)

data_2 <- df %>%
  mutate(test = "test")

Upvotes: 1

Related Questions