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
12
votes
5 answers

namespace 'rlang' 0.4.5 is being loaded, but >= 0.4.10 is required

I'm trying to install the 'lifecycle' package but rlangs is required. Upon typing install.packages('lifecyle') I get the error that I'm importing a rlangs package which is newer than required ('rlang' 0.4.5 is being loaded, but >= 0.4.10 is…
Victor Galuppo
  • 187
  • 2
  • 2
  • 8
12
votes
4 answers

What does 'Can't use `!!!` at top level.' mean and how to resolve it?

I am trying to create a function for creating lollipop plots using ggplot2. I would like to pass all argument within ... to aes() within geom_point(). However, I'd like to exclude the size argument from passing onto aes() within geom_segment() (for…
Thomas Neitmann
  • 2,552
  • 1
  • 16
  • 31
12
votes
3 answers

converting a quosure to a string in R

I've been using quosures with dplyr: library(dplyr) library(ggplot2) thing <- quo(clarity) diamonds %>% select(!!thing) print(paste("looking at", thing)) [1] "looking at ~" "looking at clarity" I really want to print out the string value…
pluke
  • 3,832
  • 5
  • 45
  • 68
12
votes
2 answers

How to filter a data frame programmatically with dplyr and tidy evaluation?

Let's say I want to filter the starwars data frame programmatically. Here's a simple example that lets me filter based on homeworld and species: library(tidyverse) # a function that allows the user to supply filters filter_starwars <-…
tws
  • 697
  • 7
  • 18
12
votes
2 answers

Tidy evaluation programming and ggplot2

Trying to write a relatively simple wrapper to produce some plots, but can not work out how to specify tidy evaluation of grouping variables specified as ... an example function that facets variables but doesn't distinguish by grouping... my_plot <-…
slackline
  • 2,295
  • 4
  • 28
  • 43
11
votes
3 answers

How to replace the deprecated ggplot2 function aes_string: accepting an arbitrary number of named strings to specify aesthetic mappings?

aes_string had some convenient behaviours that I made use of when programming with ggplot2. But aes_string has been deprecated (noticeably since ggplot2 version 3.4.0 I believe). I am struggling with how to nicely replace it. Specifically, I…
David Barnett
  • 153
  • 1
  • 9
11
votes
1 answer

no visible binding for global variable ‘.’

I'm currently co-developing an R package using devtools. We use the tidyverse %>% and associated purrr and dplyr packages within our functions. One of our functions is as follows (edited for clarity): #' Print `cust_modl` object #' #' @param x A…
user4687531
  • 1,021
  • 15
  • 30
10
votes
1 answer

How can you make tidyverse functions that support both quoted and unquoted arguments?

I know how to make functions that support quasi-quotation for an argument named 'variable' {using dplyr::enquo(variable) for unquoted function arguments} or functions that require you to quote the argument {using rlang::sym("variable")}. Is there an…
bholly
  • 103
  • 4
10
votes
3 answers

R How to use curly curly with filter or filter_?

I was answering this question where commenters suggested !!ensym, and I thought this might be a good place to use curly curly {{ but I couldn't get it to work (maybe not applicable?). How might I do this filter operation, without using filter_,…
Arthur Yip
  • 5,810
  • 2
  • 31
  • 50
10
votes
2 answers

tidy eval vs base or get() vs sym() vs as.symbol()

I have been trying to understand tidy eval or how to use variables within tidyverse for a while, but I never seem to fully grasp it. For example, I am trying to use ggplot with variable mappings. This would the base R version: library(ggplot2) var1…
burger
  • 5,683
  • 9
  • 40
  • 63
10
votes
3 answers

dplyr: mutate_at + coalesce: dynamic names of columns

I've been trying for awhile to combine mutate_at with coalesce in case in which names of columns are generated dynamically. In my example there are only five columns, but in the real data there are much more (and not all columns should be included…
RSzT
  • 307
  • 3
  • 14
10
votes
3 answers

How to feed a list of unquoted column names into `lapply` (so that I can use it with a `dplyr` function)

I am trying to write a function in tidyverse/dplyr that I want to eventually use with lapply (or map). (I had been working on it to answer this question, but came upon an interesting result/dead-end. Please don't mark this as a duplicate - this…
leerssej
  • 14,260
  • 6
  • 48
  • 57
10
votes
1 answer

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

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 …
crazybilly
  • 2,992
  • 1
  • 16
  • 42
9
votes
6 answers

dplyr tidyr – How to generate case_when with dynamic conditons?

Is there a way to dynamically/programmatically generate case_when conditions in dplyr with different column names and/or different numbers of conditions? I have an interactive script that I'm trying to convert into a function. There's a lot of…
anonymous1a
  • 785
  • 1
  • 7
  • 12
9
votes
1 answer

Understanding when to use ensym, sym vs enquo in a function

I'm trying to wrap my head around the different quo/unquo syntaxes and when each should be used. I am mostly writing functions that pass a dataframe and columns to use as argument -- to plot using ggplot or summarize/manipulate data with dplyr…
Jmac
  • 233
  • 1
  • 8
1
2
3
52 53