tidyeval

Using unquoted strings in with `dplyr` verbs: `select` and `arrange` working differently

余生颓废 提交于 2021-01-04 04:59:10
问题 I am trying to unquote a string for use in dplyr::arrange . It does not appear to work. However, it appears to work correctly in dplyr::select . Am I missing something or doing something wrong here? library(tidyverse) df <- tibble(x = c(1, 2, 3), y = c(8, 6, 3)) v <- 'y' # `select` works with `!!v` df %>% select(y) #> # A tibble: 3 x 1 #> y #> <dbl> #> 1 8 #> 2 6 #> 3 3 df %>% select(!!v) #> # A tibble: 3 x 1 #> y #> <dbl> #> 1 8 #> 2 6 #> 3 3 # `arrange` not work with `!!v` df %>% arrange(y)

Using unquoted strings in with `dplyr` verbs: `select` and `arrange` working differently

不羁岁月 提交于 2021-01-04 04:58:05
问题 I am trying to unquote a string for use in dplyr::arrange . It does not appear to work. However, it appears to work correctly in dplyr::select . Am I missing something or doing something wrong here? library(tidyverse) df <- tibble(x = c(1, 2, 3), y = c(8, 6, 3)) v <- 'y' # `select` works with `!!v` df %>% select(y) #> # A tibble: 3 x 1 #> y #> <dbl> #> 1 8 #> 2 6 #> 3 3 df %>% select(!!v) #> # A tibble: 3 x 1 #> y #> <dbl> #> 1 8 #> 2 6 #> 3 3 # `arrange` not work with `!!v` df %>% arrange(y)

no visible global function definition for ':='

南楼画角 提交于 2020-12-05 05:11:17
问题 I am writing a package that uses tidyeval. Becuase I use tidyeval I have rlang listed under imports in the description file. One of the functions contains a few lines that use := Like this: data %>% dplyr::mutate( !!New_R := AP_R_X*!!X + AP_R_Y*!!Y + AP_R_Z*!!Z, !!New_U := AP_U_X*!!X + AP_U_Y*!!Y + AP_U_Z*!!Z, !!New_F := AP_F_X*!!X + AP_F_Y*!!Y + AP_F_Z*!!Z) The code works as intended but I get the following note when running devtools::check() no visible global function definition for ':='

curly curly Tidy evaluation and modifying inputs or their names

核能气质少年 提交于 2020-08-22 14:34:42
问题 The new curly curly method of tidy evaluation is explained in this article. Several examples are given demonstrating the use of this style of non-standard evaluation (NSE). library(tidyverse) # Example 1 -------------------------- max_by <- function(data, var, by) { data %>% group_by({{ by }}) %>% summarise(maximum = max({{ var }}, na.rm = TRUE)) } starwars %>% max_by(height) starwars %>% max_by(height, by = gender) # Example 2 -------------------------- summarise_by <- function(data, ..., by

Making tidyeval function inside case_when

不羁岁月 提交于 2020-07-21 03:06:48
问题 I have a data set that I like to impute one value among others based on probability distribution of those values. Let make some reproducible example first library(tidyverse) library(janitor) dummy1 <- runif(5000, 0, 1) dummy11 <- case_when( dummy1 < 0.776 ~ 1, dummy1 < 0.776 + 0.124 ~ 2, TRUE ~ 5) df1 <- tibble(q1 = dummy11) here is the output: df1 %>% tabyl(q1) q1 n percent 1 3888 0.7776 2 605 0.1210 5 507 0.1014 I used mutate and sample to share value= 5 among value 1 and 2 like this: df1 %

Making tidyeval function inside case_when

白昼怎懂夜的黑 提交于 2020-07-21 03:06:28
问题 I have a data set that I like to impute one value among others based on probability distribution of those values. Let make some reproducible example first library(tidyverse) library(janitor) dummy1 <- runif(5000, 0, 1) dummy11 <- case_when( dummy1 < 0.776 ~ 1, dummy1 < 0.776 + 0.124 ~ 2, TRUE ~ 5) df1 <- tibble(q1 = dummy11) here is the output: df1 %>% tabyl(q1) q1 n percent 1 3888 0.7776 2 605 0.1210 5 507 0.1014 I used mutate and sample to share value= 5 among value 1 and 2 like this: df1 %