rlang

dplyr 0.7 equivalent for deprecated mutate_

半世苍凉 提交于 2019-11-28 04:07:13
问题 I cannot find in dplyr 0.7 a way to replace the mutate_ function which is going to be deprecated. The mutate_ function is useful in my use case : I store in a database (string format) many instructions (that can be filtered if needed) and apply these instructions to one or several data frames. For example : dplyr::tibble(test = "test@test") %>% dplyr::mutate_(.dots = list("test2" = "substr(test, 1, 5)", "test3" = "substr(test, 5, 5)")) Is there a way to do this with dplyr 0.7 keeping

pass function arguments to both dplyr and ggplot

大城市里の小女人 提交于 2019-11-27 14:23:57
I'm confused about how to pass function argument into dplyr and ggplot codes. I'm using the newest version of dplyr and ggplot2 Here is my code to produce a barplot (clarity vs mean price) diamond.plot<- function (data, group, metric) { group<- quo(group) metric<- quo(metric) data() %>% group_by(!! group) %>% summarise(price=mean(!! metric)) %>% ggplot(aes(x=!! group,y=price))+ geom_bar(stat='identity') } diamond.plot(diamonds, group='clarity', metric='price') error: Error in UseMethod("group_by_") : no applicable method for 'group_by_' applied to an object of class "packageIQR" For the newest

How to pass a named vector to dplyr::select using quosures?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 06:11:59
问题 Using the old select_() function, I could pass a named vector into select and change position and column names at once: my_data <- data_frame(foo = 0:10, bar = 10:20, meh = 20:30) my_newnames <- c("newbar" = "bar", "newfoo" = "foo") move_stuff <- function(df, newnames) { select_(df, .dots = newnames) } move_stuff(my_data, newnames = my_newnames) ) # this is the desired output # A tibble: 4 x 2 newbar newfoo <int> <int> 1 10 0 2 11 1 3 12 2 4 13 3 I tried doing something similar using quosures

How to parametrize function calls in dplyr 0.7?

五迷三道 提交于 2019-11-27 01:02:54
The release of dplyr 0.7 includes a major overhaul of programming with dplyr. I read this document carefully, and I am trying to understand how it will impact my use of dplyr. Here is a common idiom I use when building reporting and aggregation functions with dplyr: my_report <- function(data, grouping_vars) { data %>% group_by_(.dots=grouping_vars) %>% summarize(x_mean=mean(x), x_median=median(x), ...) } Here, grouping_vars is a vector of strings. I like this idiom because I can pass in string vectors from other places, say a file or a Shiny app's reactive UI, but it's also not too bad for

pass function arguments to both dplyr and ggplot

好久不见. 提交于 2019-11-26 16:43:50
问题 I'm confused about how to pass function argument into dplyr and ggplot codes. I'm using the newest version of dplyr and ggplot2 Here is my code to produce a barplot (clarity vs mean price) diamond.plot<- function (data, group, metric) { group<- quo(group) metric<- quo(metric) data() %>% group_by(!! group) %>% summarise(price=mean(!! metric)) %>% ggplot(aes(x=!! group,y=price))+ geom_bar(stat='identity') } diamond.plot(diamonds, group='clarity', metric='price') error: Error in UseMethod("group

How to parametrize function calls in dplyr 0.7?

喜夏-厌秋 提交于 2019-11-26 08:11:11
问题 The release of dplyr 0.7 includes a major overhaul of programming with dplyr. I read this document carefully, and I am trying to understand how it will impact my use of dplyr. Here is a common idiom I use when building reporting and aggregation functions with dplyr: my_report <- function(data, grouping_vars) { data %>% group_by_(.dots=grouping_vars) %>% summarize(x_mean=mean(x), x_median=median(x), ...) } Here, grouping_vars is a vector of strings. I like this idiom because I can pass in

Use variable names in functions of dplyr

纵饮孤独 提交于 2019-11-26 02:20:02
问题 I want to use variable names as strings in functions of dplyr . See the example below: df <- data.frame( color = c(\"blue\", \"black\", \"blue\", \"blue\", \"black\"), value = 1:5) filter(df, color == \"blue\") It works perfectly, but I would like to refer to color by string, something like this: var <- \"color\" filter(df, this_probably_should_be_a_function(var) == \"blue\"). I would be happy, to do this by any means and super-happy to make use of easy-to-read dplyr syntax. 回答1: For dplyr