Last active
July 14, 2019 05:18
-
-
Save hypercompetent/cad03dfeca5582ab78250b475e2364d0 to your computer and use it in GitHub Desktop.
Notes for tidy evaluation based on strings as sources of column names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tidyeval notes | |
library(dplyr) | |
library(rlang) | |
library(tasic2016data) | |
# one character element: | |
test <- "primary_type_id" | |
expr_test <- parse_expr(test) | |
tasic_2016_anno %>% | |
group_by(!!expr_test) %>% | |
summarise(x = n()) | |
# or | |
tasic_2016_anno %>% | |
group_by(!!parse_expr(test)) %>% | |
summarise(x = n()) | |
# one or more character elements | |
test <- c("primary_type_id","secondary_type_id") | |
expr_test <- lapply(test, parse_expr) | |
tasic_2016_anno %>% | |
group_by(!!!expr_test) %>% | |
summarise(x = n()) | |
# a single entry from multiple elements | |
test <- c("primary_type_id","secondary_type_id") | |
expr_test <- lapply(test, parse_expr) | |
tasic_2016_anno %>% | |
group_by(!!expr_test[[1]]) %>% | |
summarise(x = n()) | |
# Filtering: | |
test <- "primary_type_id" | |
test_targets <- c(1:5) | |
tasic_2016_anno %>% | |
filter(!!parse_expr(test) %in% test_targets) %>% | |
group_by(!!parse_expr(test)) %>% | |
summarise(x = n()) | |
# or | |
expr_test <- parse_expr(test) | |
tasic_2016_anno %>% | |
filter(!!expr_test %in% test_targets) %>% | |
group_by(!!expr_test) %>% | |
summarise(x = n()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: the
tasic2016data
package can be installed with: