Using a variable with filter/endswith instead of hard coding


#1

Is there a way that I can call in a variable from another table with endsWith() instead of hard coding what I am filtering on? I am hoping to make the code dynamic and not fixed. I would hate to repeat the code, changing out what I am filtering on. Is there a way around this?

Hard coded:

    dplyr::filter(endsWith(EVENT_ID, "201"))```

What I am trying to do:

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

This code is apart of a loop, hence the i.

#2

I can't quite tell from your example whether it's the content or the variable you want to vary. If the former, see partial matching section here, for example, using str_detect(). If it's the variable on which you're filtering itself you want to change, this might be a good use case for tidy eval/quasiquotation.

http://dplyr.tidyverse.org/articles/programming.html