What is the correct way to put quoted strings in rlang functions?

Multi tool use
up vote
0
down vote
favorite
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()))
r dplyr tidyverse lubridate rlang
add a comment |
up vote
0
down vote
favorite
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()))
r dplyr tidyverse lubridate rlang
Why do you want to usequo
? it works fine without it
– Moody_Mudskipper
Nov 10 at 13:20
To go one step further from @Moody_Mudskipper, I dont think you need any quasiquotaton in your example. if you take out bothquo
and!!
, you will get the same result. If you passed a variable that you would want to filter instead ofdep_date
then you would need QQ or use the NSE escape hatches
– Jrakru56
Nov 10 at 16:19
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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()))
r dplyr tidyverse lubridate rlang
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()))
r dplyr tidyverse lubridate rlang
r dplyr tidyverse lubridate rlang
edited Nov 10 at 12:13
asked Nov 10 at 12:08
lim-lim
103
103
Why do you want to usequo
? it works fine without it
– Moody_Mudskipper
Nov 10 at 13:20
To go one step further from @Moody_Mudskipper, I dont think you need any quasiquotaton in your example. if you take out bothquo
and!!
, you will get the same result. If you passed a variable that you would want to filter instead ofdep_date
then you would need QQ or use the NSE escape hatches
– Jrakru56
Nov 10 at 16:19
add a comment |
Why do you want to usequo
? it works fine without it
– Moody_Mudskipper
Nov 10 at 13:20
To go one step further from @Moody_Mudskipper, I dont think you need any quasiquotaton in your example. if you take out bothquo
and!!
, you will get the same result. If you passed a variable that you would want to filter instead ofdep_date
then you would need QQ or use the NSE escape hatches
– Jrakru56
Nov 10 at 16:19
Why do you want to use
quo
? it works fine without it– Moody_Mudskipper
Nov 10 at 13:20
Why do you want to use
quo
? it works fine without it– Moody_Mudskipper
Nov 10 at 13:20
To go one step further from @Moody_Mudskipper, I dont think you need any quasiquotaton in your example. if you take out both
quo
and !!
, you will get the same result. If you passed a variable that you would want to filter instead of dep_date
then you would need QQ or use the NSE escape hatches– Jrakru56
Nov 10 at 16:19
To go one step further from @Moody_Mudskipper, I dont think you need any quasiquotaton in your example. if you take out both
quo
and !!
, you will get the same result. If you passed a variable that you would want to filter instead of dep_date
then you would need QQ or use the NSE escape hatches– Jrakru56
Nov 10 at 16:19
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238792%2fwhat-is-the-correct-way-to-put-quoted-strings-in-rlang-functions%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
atPuvWBy9iSbcBbN3KK9hQDj YvbdQxckte,sFaTReGS,crZUVkapQ 0wVF4JjlKP1NQ8LzzGJJ,G97b vnF2WyrRy cVvT,zD4,OA2Sgd u
Why do you want to use
quo
? it works fine without it– Moody_Mudskipper
Nov 10 at 13:20
To go one step further from @Moody_Mudskipper, I dont think you need any quasiquotaton in your example. if you take out both
quo
and!!
, you will get the same result. If you passed a variable that you would want to filter instead ofdep_date
then you would need QQ or use the NSE escape hatches– Jrakru56
Nov 10 at 16:19