quasiquotes

using `rlang` quasiquotation with `dplyr::_join` functions

梦想与她 提交于 2021-02-19 05:45:26
问题 I am trying to write a custom function where I use rlang 's quasiquotation. This function also internally uses dplyr 's join functions. I have provided below a minimal working example that illustrated my problem. # needed libraries library(tidyverse) # function definition df_combiner <- function(data, x, group.by) { # check how many variables were entered for this grouping variable group.by <- as.list(rlang::quo_squash(rlang::enquo(group.by))) # based on number of arguments, select `group.by`

Non-standard evaluation and quasiquotation in dplyr() not working as (naively) expected

不想你离开。 提交于 2019-12-29 00:41:09
问题 I am trying to search a database and then label the ouput with a name derived from the original search, "derived_name" in the reproducible example below. I am using a dplyr pipe %>% , and I am having trouble with quasiquotation and/or non-standard evaluation. Specifically, using count_colname , a character object derived from "derived_name" , in the final top_n() function fails to subset the dataframe. search_name <- "derived_name" set.seed(1) letrs <- letters[rnorm(52, 13.5, 5)] letrs_count

Non-standard evaluation and quasiquotation in dplyr() not working as (naively) expected

亡梦爱人 提交于 2019-12-29 00:41:06
问题 I am trying to search a database and then label the ouput with a name derived from the original search, "derived_name" in the reproducible example below. I am using a dplyr pipe %>% , and I am having trouble with quasiquotation and/or non-standard evaluation. Specifically, using count_colname , a character object derived from "derived_name" , in the final top_n() function fails to subset the dataframe. search_name <- "derived_name" set.seed(1) letrs <- letters[rnorm(52, 13.5, 5)] letrs_count

Pass multiple calling arguments to a formal argument in dplyr custom function without using “…”

若如初见. 提交于 2019-12-14 00:26:44
问题 To make a custom function flexible to receiving one or more calling arguments per formal argument I currently rely on "...": library(dplyr) foo <- function(data, ..., dv){ groups <- enquos(...) dv <- enquo(dv) data %>% group_by(!!!groups) %>% summarise(group_mean = mean(!!dv)) } mtcars %>% foo(am, dv = mpg) mtcars %>% foo(vs, am, dv = mpg) But "..." obscures the logic of the function, and it could not be used in a custom function with 2 or more formal arguments requiring multiple calling

Pass multiple calling arguments to a formal argument in dplyr custom function without using “…”

此生再无相见时 提交于 2019-12-04 18:15:22
To make a custom function flexible to receiving one or more calling arguments per formal argument I currently rely on "...": library(dplyr) foo <- function(data, ..., dv){ groups <- enquos(...) dv <- enquo(dv) data %>% group_by(!!!groups) %>% summarise(group_mean = mean(!!dv)) } mtcars %>% foo(am, dv = mpg) mtcars %>% foo(vs, am, dv = mpg) But "..." obscures the logic of the function, and it could not be used in a custom function with 2 or more formal arguments requiring multiple calling arguments. Is there a way to write the above function to utilize a formal argument (e.g., "groups") rather

Non-standard evaluation and quasiquotation in dplyr() not working as (naively) expected

末鹿安然 提交于 2019-11-28 12:41:09
I am trying to search a database and then label the ouput with a name derived from the original search, "derived_name" in the reproducible example below. I am using a dplyr pipe %>% , and I am having trouble with quasiquotation and/or non-standard evaluation. Specifically, using count_colname , a character object derived from "derived_name" , in the final top_n() function fails to subset the dataframe. search_name <- "derived_name" set.seed(1) letrs <- letters[rnorm(52, 13.5, 5)] letrs_count.df <- letrs %>% table() %>% as.data.frame() count_colname <- paste0(search_name, "_letr_count")