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









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()))









share|improve this question























  • 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















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()))









share|improve this question























  • 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













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()))









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 12:13

























asked Nov 10 at 12:08









lim-lim

103




103











  • 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

















  • 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
















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


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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














































































這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3