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

rlang::hash cannot differentiate between arrow queries

I use the memoise package to cache queries to an arrow dataset but I sometimes get mismatches/"collisions" in hashes and therefore the wrong values are returned. I have isolated the problem and replicated it in the MWE below. The issue is that the…
David
  • 9,216
  • 4
  • 45
  • 78
3
votes
2 answers

tidy evaluation cannot work in function in R

Context I am learning tidy evaluation on this website, And I see an example: x <- sym("height") expr(transmute(starwars, bmi = mass / (!! x)^2)) #> transmute(starwars, bmi = mass/(height)^2) transmute(starwars, bmi = mass / (!! x)^2) #> # A…
zhiwei li
  • 1,635
  • 8
  • 26
3
votes
0 answers

Preserve whitespace in cli::cli_abort messages from R package cli?

I am using cli::cli_abort to handle errors. As context for an error message, I am trying to print the contents of a matrix. I can achieve this via capture.output, though when the message is processed by cli::cli_abort the whitespace gets collapsed…
toni
  • 31
  • 3
3
votes
0 answers

R Markdown stops rendering when encountering a chunk with base R graphics

sessionInfo() R version 4.2.1 (2022-06-23) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Monterey 12.3 Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib locale: [1]…
haymourt
  • 31
  • 2
3
votes
1 answer

Using rlang double curly braces {{ in data.table

Problem The {{}} operator from the rlang package makes it incredibly easy to pass column names as function arguments (aka Quasiquotation). I understand rlang is intended to work with tidyverse, but is there a way to use {{}} in data.table? Intended…
rafa.pereira
  • 13,251
  • 6
  • 71
  • 109
3
votes
1 answer

Dynamic variables names in dplyr function across multiple columns

I am trying to write a function that uses dplyr::summarise to obtain means of multiple columns of a data frame and assign dynamic names to the summarised columns using the new rlang glue syntax and := operator. Here's a simple example of my problem…
Shellstar
  • 33
  • 2
3
votes
1 answer

R metaprogramming: pass expression/quosure to function that partially accesses local frame

I will use the following example to explain my question. But the question is not only about this specific example, but more general about meta-programming in R. I have two specific functions to make plots Specific function 1 draw_hists <-…
englealuze
  • 1,445
  • 12
  • 19
3
votes
1 answer

Error when R package building: `:=` can only be used within dynamic dots

So I've written this function here which renames the first column in a data frame: { df %>% rename({{newname}} := colnames(df[1])) } It ran completely fine. Now when I moved this function to a package I' m building, it suddenly started…
rjwg
  • 41
  • 3
3
votes
1 answer

Extract a function-call expression's arguments with names

Let's say I have an expression representing a function call, where some arguments are named and some are positional. expr <- quote(mean(1:5, na.rm = TRUE)) Would it be possible to extract the arguments and all of their…
Wasabi
  • 2,879
  • 3
  • 26
  • 48
3
votes
1 answer

env_parent(): different results when using default argument or when passing explicitly default argument

I have noticed different behavior when using env_parent() from rlang package and when using env_parent(caller_env()), although caller_env() is a default argument for env_parent() first parameter: library(rlang) env_parent #> function (env =…
gss
  • 1,334
  • 6
  • 11
3
votes
2 answers

R: Could I make the execution environment of a function permanent?

I'm studying R environments but I have got a question reading the "Advanced R" book by Hadley Wickham. Is it possible to make the execution environment of a function permanent? I will try to explain the why of my question. When Wickham explains how…
3
votes
1 answer

In R, how can I use a quoting function inside another function?

I am trying to figure out why fun1() works but fun2() throws an error. I think it has something to do with the way in which rlang handles the quoting/unquoting of the x variable, but I'm not really sure. This is a toy example. I am trying to…
Caddisfly
  • 1,290
  • 6
  • 24
3
votes
1 answer

Tidyeval: How to pass a list with quoted elements to a nested function without user quoting?

Say I have two functions and I want to nest a within b: library(dplyr) library(rlang) a <- function(var, values){ filter(iris, {{var}} %in% values) } a(Species, "virginica") %>% head() Sepal.Length Sepal.Width Petal.Length Petal.Width …
LMc
  • 12,577
  • 3
  • 31
  • 43
3
votes
1 answer

Have a function accept a list column of parameters

Related to Pass a list of lists of unquoted character parameters to an apply/map/pmap call. I have a function that looks like this: causal_med_so <- function(predictor, mediator, outcome, data, ...){ predictor <- rlang::ensym(predictor) mediator…
Raoul Duke
  • 435
  • 3
  • 13
3
votes
0 answers

Error in h(simpleError(msg, call)) : error in evaluating the argument 'object' in selecting a method for function 'summary'

I'm trying to implement an existing code on Github but i still get an error that I don't know where it did came from or how to fix it. Here is the function : AdstockRate<-function(Data,Impact,Ads){ …
Euler
  • 29
  • 1
  • 6