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
5
votes
1 answer

Problem programming with dplyr--column which is definitely a vector being picked up as a formula

I'm writing a function to reproduce several charts that will all have similar formatting (and other stuff) using highcharter. I want to be able select different columns of the data set should the names change or if I want to be doing something…
Ben G
  • 4,148
  • 2
  • 22
  • 42
5
votes
2 answers

Using mutate with map2 and exec instead of invoke_map

This example in "R for Data Science" uses invoke_map which is now retired. sim <- tribble( ~f, ~params, "runif", list(min = -1, max = 1), "rnorm", list(sd = 5), "rpois", list(lambda = 10) ) sim %>% mutate(sim = invoke_map(f, params, n =…
stats101
  • 53
  • 3
5
votes
3 answers

curly curly tidy evaluation programming with multiple inputs and custom function across columns

My question is similar to this question but I need to apply a more complex function across columns and I can't figure out how to apply Lionel's suggested solution to a custom function with a scoped verb like filter_at() or a filter()+across()…
lost
  • 1,483
  • 1
  • 11
  • 19
5
votes
1 answer

Tidy Eval: Using {{var}} inside a nesting function not possible?

I was trying to use tidyr::complete inside my function while providing the variable names using {{}}. This works fine, however, when I add a nesting function to combine two variables I get an error. Please see the minimal example…
jpquast
  • 333
  • 2
  • 8
5
votes
2 answers

In writing an R package, using the flowCore::transform function, can I both use a variable name as text and get the actual value?

I am trying to pass on an argument to a function, which is a string but must be evaluated both for it's name (symbol?) and it's value (see example below). So far I am able to use base::get to get the actual value, but the assignment in…
FM Kerckhof
  • 1,270
  • 1
  • 14
  • 31
5
votes
1 answer

Tidyverse, Rlang and tidyeval: Bang bang (!!) failing inside function, but it appears to work without quotation

I am running a function on a long database (full_database) with two major groups where I need to perform various linear models on multiple subsets, per group. Then, I extract the R^2, the adjusted R^2 and the p.value into a dataframe where each row…
filcfig
  • 75
  • 3
5
votes
1 answer

Rlang: how to treat strings as symbols

Once again I'm baffled by the documentation of rlang and the error messages. I've tried 20 different iterations of this using double and triple bangs, :=, quo, enquo, ensym, and every other unclearly named rlang function. IF you sense frustration…
jzadra
  • 4,012
  • 2
  • 26
  • 46
5
votes
1 answer

using `rlang::exec` with functions that use `rlang::ensym`

I am trying to write a custom function which is a bit more complicated so for the sake of simplicity I have created toy examples. Let's say I want to write a function that- automatically decides the appropriate function to run: for example, a…
Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51
5
votes
1 answer

could not find function "switch_lang"

getting this error, does anyone have an idea what is triggering it? #### sc is a spark…
Mouad_Seridi
  • 2,666
  • 15
  • 27
5
votes
1 answer

How to test null or missing for enquos-type quosures

There's a quite subtle (and very confusing) distinction in rlang that... quosures are not quosure objects! In other terms: quo() and enquo() return a quosure quos() and enquos() return a quosureS, not a quosure (is_quosure(enquos(...)) returns…
Matifou
  • 7,968
  • 3
  • 47
  • 52
5
votes
2 answers

How do I pass a dynamic variable name created using enquo() to dplyr's mutate for evaluation?

I'm creating a workflow that contains the same piping steps of renaming, selecting by, then mutating all using a name I provide prior to the pipe. I have had success using enquo() and !!(bang bang) to rename to my desired string and then select it…
Adam Kemberling
  • 301
  • 1
  • 11
5
votes
1 answer

How to use dplyr programming syntax to create and evaluate variable names

I would like to dynamically input a variable name using dplyr programming syntax, however, as many have described this can be quite confusing. I've played around with various combinations of quo/enquo !! etc. to no avail. Here is the simplest form…
TDP
  • 335
  • 1
  • 3
  • 9
5
votes
2 answers

Tidyeval: pass list of columns as quosure to select()

I want to pass a bunch of columns to pmap() inside mutate(). Later, I want to select those same columns. At the moment, I'm passing a list of column names to pmap() as a quosure, which works fine, although I have no idea whether this is the "right"…
Oliver
  • 1,098
  • 1
  • 11
  • 16
5
votes
2 answers

Using data.table and tidy eval together: why group by does not work as expected, why is ~ inserted?

I do not have a pressing use case but would like to understand how tidy eval and data.table may work together. I have working alternative solutions so I am mostly interested in the why because I hope to have a better understanding of tidy eval in…
Ildi Czeller
  • 190
  • 1
  • 9
5
votes
1 answer

How can I count the number of variables in an R quosure?

Let's say I have a function that takes in a data frame and a varying number of variables from that data frame using non-standard evaluation (NSE). Is there a faster/more straightforward way to count the number of provided variables than select()ing…
Jeffrey Girard
  • 761
  • 4
  • 20