I have a tbl_df data set called ds, and I want to write a function so that I can filter a column based on some String value. Here is my attempt:
myCol <- as.name(names(ds)[5]) # define which col to pass to the function
myFunction <- function(ds, myCol, myString="XXXX" ){
myQuant <- ds %>%
filter(myCol %in% myString )%>%
group_by(x)%>%
summarize(count = n())
return(myQuant)
}
This produces the following error:
Error during wrapup: 'match' requires vector arguments
If extract the filtering block outside the function and pass the arguments manually, it works fine.
I guess all what the filter function requires is a column name, so why doesn't like it this way?