Questions tagged [rlang]

rlang is an R package for creating tidy evaluation interfaces and manipulating language and environment objects. It is a utility package underlying many of the tidyverse family of packages.

rlang is an R package for creating tidy evaluation interfaces and manipulating language and environment objects. It is a utility package underlying many of the tidyverse family of packages.

rlang offers tools for building an alternate non-standard evaluation (NSE) interface, redubbed "tidy eval", based on quasiquotation. Its basic operators are quo() for quoting and !! (said "bang-bang") for unquoting. The tidy eval framework is now integrated in many tidyverse packages, including dplyr and tidyr.

786 questions
7
votes
2 answers

How to display a warning only once per session?

There is a functionality in my package that should be used with caution. The user should be aware of this but if he/she thinks that the situation is OK then it would be bothering to show the warning each time the function is called. I often see…
Dan Chaltiel
  • 7,811
  • 5
  • 47
  • 92
7
votes
2 answers

how to unquote (!!) inside `map` inside `mutate`

I'm modifying nested data frames inside of foo with map2 and mutate, and I'd like to name a variable in each nested data frame according to foo$name. I'm not sure what the proper syntax for nse/tidyeval unquotation would be here. My…
lost
  • 1,483
  • 1
  • 11
  • 19
7
votes
5 answers

Create R function using dplyr::filter problem

I've looked at other answers but cannot find a solution for the code below to work. Basically, I'm creating a function that inner_join the two data frame and filter based on a column inputted in the function. The problem is that the filter part of…
x85ms16
  • 587
  • 7
  • 17
7
votes
3 answers

dplyr/rlang: parse_expr with multiple expressions

dplyr/rlang: parse_expr with multiple expressions For example if i want to parse some string to mutate i can e1 = "vs + am" mtcars %>% mutate(!!parse_expr(e1)) But when i want to parse any text with special characters like "," it will give me an…
user9672798
  • 113
  • 1
  • 4
7
votes
1 answer

Tidy evaluation when column names are stored in strings

I need to filter a table by a logical column (or, more precisely, by its negation), but the name of the column may vary. It's easy when I know their names beforehand: tb = tibble( id = 1:4, col1 = c(TRUE, TRUE, FALSE, FALSE), col2 = c(TRUE,…
Luiz Rodrigo
  • 936
  • 1
  • 7
  • 19
7
votes
2 answers

Use dplyr::case_when with arguments programmatically

I'd like to be able to use dplyr's case_when in a programmatic way to replace base R cut()function. Currently, case_when can be used with an external argument through NSE like : library(dplyr) library(rlang) patterns <- list( x <= 2 ~ "<=2", x…
RobinCura
  • 410
  • 2
  • 8
6
votes
3 answers

R dplyr: how to use ... with summarize(across()) when ... will refer to a variable name within the data?

I want to have a flexible function using summarize in which: the aggregation function is given by user the aggregation function might use further arguments which refer to variables within the data itself. A good example is the user providing…
Matifou
  • 7,968
  • 3
  • 47
  • 52
6
votes
2 answers

Replacing group_by_at(NULL) using across

Before, I used group_by_at to group by a vector of strings or by NULL: library(tidyverse) grouping_1 <- c("cyl", "vs") grouping_2 <- NULL mtcars %>% group_by_at(grouping_1) mtcars %>% group_by_at(grouping_2) The help of group_by_at indicates…
danilinares
  • 1,172
  • 1
  • 9
  • 28
6
votes
1 answer

Specify the dots argument when calling a tidyselect-using function without needing to specify the preceding arguments

Here's a simplified version of a function I have in a package that uses the ... argument and tidyselect to select variables: # this toy function just selects the ... variables foo <- function(dat = mtcars, ...){ expr <- rlang::expr(c(...)) …
Sam Firke
  • 21,571
  • 9
  • 87
  • 105
6
votes
1 answer

base R substitute names of the arguments to function call

The ultimate goal in the question is to construct the following unevaluated call using r's computing on the language, where list, a_name and 50L are provided from parameters. list(a_name = 50L) Which internally looks like str(quote(list(a_name =…
jangorecki
  • 16,384
  • 4
  • 79
  • 160
6
votes
1 answer

using `rlang` NSE to group by multiple variables

I am trying to write a custom function that uses rlang's non-standard evaluation to group a dataframe by more than one variable. This is what I've- library(rlang) # function definition tryfn <- function(data, groups, ...) { # preparing data df…
Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51
6
votes
2 answers

How to construct arguments for case_when from data frame?

I'm trying to create many different possible weighting schemes based on temperature. I created a data frame with all possible combinations of 8 vectors (each vector represents a temperature range). So the columns of the data frame are a specific…
Giovanni Colitti
  • 1,982
  • 11
  • 24
6
votes
2 answers

Problem updating rlang when installing dev version of a package

I'm trying to install the dev version of tidyr. When I try devtools::install_github("tidyverse/tidyr") or remotes::install_github("tidyverse/tidyr"), I get the following error: > devtools::install_github("tidyverse/tidyr") Downloading GitHub repo…
user51462
  • 1,658
  • 2
  • 13
  • 41
6
votes
1 answer

How to use rlang operators in a package?

I am writing a package that uses tidyverse functions, i.e. that use non-standard evaluation, like dplyr::filter for example: setMethod("filter_by_id", signature(x = "studies", id = "character"), definition = function(x, id) { …
Ramiro Magno
  • 3,085
  • 15
  • 30
6
votes
1 answer

Deparse, substitute with three-dots arguments

Let consider a typical deparse(substitute( R call: f1 <-function(u,x,y) {print(deparse(substitute(x)))} varU='vu' varX='vx' varY='vy' f1(u=varU,x=varX,y=varY) That results in [1] "varX" which is what we expect and we want. Then, comes the…
beuhbbb
  • 257
  • 3
  • 14