I'm trying to build a subset function in R that will accept dataframes as well as column names and running into issues using the lazyeval approach outlined here. Here's my code:
iris_fun <- function(df, selection_var, selection_input){
temp <- subset(df, ~.data[[.env$selection_var]] == .env$selection_input)
return(temp)
}
When I attempt to call this with:
iris_fun(iris, "Species", "setosa")
I get an error message:
Error in subset.data.frame(df, ~.data[[.env$selection_var]] == selection_input) : 'Subset' must be logical
Advice appreciated!