Using Column Name as a Function with dplyr

I'm sure this is an elementary question but I'm trying to build a function that takes in a column name as an argument. When I run the function with the column name as a variable, it doesn't recognize it. It just creates a column aptly named 'column'. Is there a trick I'm missing?

add_category <- function(file_name, column) {
file_name <- file_name %>%
mutate( column = tolower(column),
Category = case_when (
str_detect(column,"accessories")==TRUE ~ "Accessories"

Sort_Filter_10 <- add_category(Sort_Filter_10, Page)

You've stumbled into the world of non-standard evaluation (NSE), which is dealt with via tidyeval:

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.