Using a variable in filter() and endswith()

Is there anyway that I call in a variable from another table into endswith() instead of hard coding what I am filtering on? I am trying to make it dynamic and not fixed.

Hardcoded:

R<-  dummyTable <- accTable %>%
    dplyr::filter(endsWith(EVENT_ID, "201"))

What I want:

R<-  dummyTable <- accTable %>%
    dplyr::filter(endsWith(courseNumTable$COURSE_NUMBER, courseNumTable$COURSE_NUMBER[1,1]))

the data in courseNumTable has been changed to characters. I have tried the get() function inside endsWith().

I'm confused by the question. Is it possible to provide a fully reproducible example? (i.e. Data and code that others can run.)

1 Like

try this:

var_courseNum <- quo(courseNumTable$COURSE_NUMBER)
var_courseNumPattern <- quo(courseNumTable$COURSE_NUMBER[1,1])

dummyTable <- accTable %>%
dplyr::filter(endsWith(!!var_courseNum, !!var_courseNumPattern))

suggestion: just to be consistent, you should use ends_with instead of endsWith...