I am writing a fuction that I will use regularly to filter for dates and names in our database (and then to perform some monthly counting/calculations on them).
I would like to know what is the correct way to insert and evaluate strings within rlang
functions in this case?
Am I doing right by using quo
to put strings into the fuction?
Example:
business_flights = tibble(passanger_name=rep(c(rep("John RED",3),rep("Mary ORANGE",3)),4),
dep_date=seq(from = lubridate::ymd('2005-04-07'),
to = lubridate::ymd('2025-03-22'), length.out = 24),
flight_num = sample(seq(from = 99, to = 1999, by = 30), size = 24, replace = TRUE))
filter_flights = function(mytibble, name, date0, date1) {
require(tidyverse); require(lubridate)
flights_filtered = mytibble %>%
filter(dep_date >= !!date0, dep_date < !!date1,
grepl(!!name, passanger_name))
View(flights_filtered)
}
filter_flights(mytibble = business_flights,
name = quo("RED"),
date0 = quo("2005-10-13"),
date1 = quo(today()))