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
3 answers

rlang: Get names from ... with colon shortcut in NSE function

I'm writing a package of functions for making tables of demographics data. I have one function, abbreviated below, where I need to take in several columns (...) on which I'll gather a data frame. The trick is I'd like to keep those columns' names in…
camille
  • 16,432
  • 18
  • 38
  • 60
5
votes
1 answer

Escape overscoping in the tidyeval framework

If I want to make overscoping explicit, I can use the .data pronoun like this library(dplyr) cyl <- 3 transmute(as_tibble(mtcars), cyl_plus_one = .data$cyl + 1) #> # A tibble: 32 x 1 #> cyl_plus_one #> #> 1 7 #> 2 …
Lorenz Walthert
  • 4,414
  • 1
  • 18
  • 24
5
votes
2 answers

How to evaluate a constructed string with non-standard evaluation using dplyr?

I have read several guides on programming with dplyr now and I am still confused about how to solve the problem of evaluating constructed/concatenated strings with non-standard evaluation (NSE). I realize that there are better ways to solve this…
Jeffrey Girard
  • 761
  • 4
  • 20
5
votes
2 answers

Rename in dplyr 0.7+ function

I am having difficulty renaming columns in a function using dplyr. I have already found helpful posts on nonstandard evaluation and the use of enquo (e.g., http://dplyr.tidyverse.org/articles/programming.html and Changing names of resulting…
Daniel
  • 415
  • 1
  • 6
  • 16
5
votes
3 answers

How to pass strings denoting expressions to dplyr 0.7 verbs?

I would like to understand how to pass strings representing expressions into dplyr, so that the variables mentioned in the string are evaluated as expressions on columns in the dataframe. The main vignette on this topic covers passing in quosures,…
Paul
  • 3,321
  • 1
  • 33
  • 42
4
votes
2 answers

How to convert value to numeric and filter out NAs within function using curly curly?

I'd like to take a tibble (or dataframe), convert one of the columns to numeric, only select the same column plus a third column, and filter out NAs. Given the following data: library(tidyverse) set.seed(1) mytib <- tibble(a = as.character(c(1:5,…
Tea Tree
  • 882
  • 11
  • 26
4
votes
2 answers

Inject Expression from One Environment and Evaluate in Another

Update It turns out that the function rlang::expr_interp() essentially meets my goal. unquo_2 <- function(expr, inj_env = rlang::caller_env(), eval_env = NULL) { # Capture verbatim the argument passed to 'expr'... expr_quo <-…
Greg
  • 3,054
  • 6
  • 27
4
votes
2 answers

Error when using curly-curly (`{{ }}`) operator with `if` clause

I'm struggling to understand how to use the {{ }} operator to pass bare variable names in custom functions. I get an error when I use the operator in conjunction with an if clause. This function works: f <- function(.data, .vars=NULL){ …
Claudio
  • 1,229
  • 6
  • 11
4
votes
2 answers

Issue with selecting negative values in dplyr with embrace {{ arg }}

I have an issue with selecting negative columns based on a variable. I found a similar issue reported here: https://github.com/tidyverse/dplyr/issues/4813 but the provided solution does not work (see repex below). If anyone knows a workaround, that…
Baraliuh
  • 2,009
  • 5
  • 11
4
votes
0 answers

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

I'm setting up my R environment. I got the following error: Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : namespace 'rlang' 0.4.9 is being loaded, but >= 0.4.10 is required Calls: ...…
Aragaki
  • 41
  • 1
  • 3
4
votes
2 answers

Programming with dplyr: Renaming a column with variable using glue syntax

I've read through Programming with dplyr and understand that rename() and select() use tidy selection. I'm trying to combine this with the glue syntax to create a custom function using the new double curly syntax (rlang v0.4.0), however I'm getting…
Alwin
  • 321
  • 2
  • 14
4
votes
2 answers

rlang double curly braces within lm() formula

Is it possible to use the rlang tidy evaluation operator {{ within an lm formula? I know that you can use the double curly braces to define a general function such as this: my_scatter <- function(df, xvar, yvar) { ggplot(df) + …
user11151932
  • 223
  • 1
  • 5
4
votes
1 answer

R {dplyr}: `rename` or `mutate` data.frames in `rowwise` list-column with different column names on LHS

I'm playing around with list-columns of data.frames with {dplyr} 1.0.0 and I'm wondering whether it is possible to rename() and mutate() columns in each data.frame without leaving the pipe when the nested data.frame is grouped rowwise. Why do I want…
TimTeaFan
  • 17,549
  • 4
  • 18
  • 39
4
votes
1 answer

Why doesn't .env pronoun work inside dplyr::slice_max?

The .env pronoun used to refer to objects in an environment (as opposed to inside a data.frame) works well inside other dplyr verbs but returns an error in slice_max. Why? Consider the following functions: library(dplyr) #> #> Attaching package:…
Giovanni Colitti
  • 1,982
  • 11
  • 24
4
votes
1 answer

mutate a variable with curly-curly

I've used curly-curly with group_by and summarise as described in the rlang announcement. But I can't get it to work when mutating a variable in place. What's the best way to do this currently with dplyr? Say I want to supply an unquoted column…
Sam Firke
  • 21,571
  • 9
  • 87
  • 105