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

dplyr, rlang: Unable to predict if minor varients of passing names to nested dplyr functions will work

Data for reproducibility .i <- tibble(a=2*1:4+1, b=2*1:4) This function is supposed to take its data and other arguments as unquoted names, find those names in the data, and use them to add a column and filter out the top row. It does not work.…
andrewH
  • 2,281
  • 2
  • 22
  • 32
0
votes
1 answer

rlang: The assignment form of quo, documentation, finding of. Or something

A lot of the help page examples for quo take forms like this one, assigning an output of quo to quo: quo <- quo(letters) quo <- quo(toupper(!! quo)) quo eval_tidy(quo) It seems clear that these assignments do not overwrite the quo function (since…
andrewH
  • 2,281
  • 2
  • 22
  • 32
0
votes
1 answer

Error in readxl::read_excel: is_null(n) : object 'rlang_is_null' not found

When trying to run the sample code given here: xlsx_example <- readxl_example("datasets.xlsx") read_excel(xlsx_example) I get the error Error in is_null(n) : object 'rlang_is_null' not found Info about my R session: sessionInfo() R version 3.4.2…
Valentin_Ștefan
  • 6,130
  • 2
  • 45
  • 68
0
votes
1 answer

How do I use the variables from rlang::UQS in a custom function?

I am still trying to understand quosures in R, but I do not understand why the substitution in the function below fails. my.toggle <- function(toggle) { if (toggle) { print("yes") } else { print("no") } } fn.args <- list(toggle =…
Jake Fisher
  • 3,220
  • 3
  • 26
  • 39
0
votes
1 answer

Referential transparency in dplyr::filter: making column name variable

Core question (what it seems to boil down to) How do I construct a call to rlang::quo with the "left" instead of the "right" side of the expression being referentially transparent Taken from the help page of rlang::quo, this works quo(foo(!!…
Rappster
  • 12,762
  • 7
  • 71
  • 120
0
votes
1 answer

Binding functions to environment to access stored variables, what are the downsides?

Problem: I need a function which takes only one argument, but needs access to some other variables. I don't want to store these in the .GlobalEnv. Current Solution: Use a function which takes all needed arguments, that create another function which…
AaronP
  • 185
  • 10
0
votes
1 answer

Evaluating a function that is an argument in another function using quo() in R

I have made a function that takes as an argument another function, the argument function takes as its argument some object (in the example a vector) which is supplied by the original function. It has been challenging to make the function call in the…
Jonno Bourne
  • 1,931
  • 1
  • 22
  • 45
0
votes
2 answers

Writing a function in R to group by variable column from a data frame

I am trying to write a function that will allow me to produce descriptive statistics by grouping across multiple factors in a data frame. I have spent way too many hours trying to get my function to recognize the by variables I am selecting. Here is…
Sam
  • 468
  • 8
  • 9
0
votes
0 answers

Create conjunction of expressions from column list

I want to create a conjunction expression from a char vector. i.e. given a vector like c("a", "b", "c"). Ultimately I want to pass it to dplyr::filter Here is my attempt: makeNonNAConjunctionExpr = function(predictors) { # Given a char vector…
Sid
  • 420
  • 1
  • 6
  • 11
0
votes
1 answer

readr: extract value from column

I am using readr's read_delim like so: focals <- read_delim('~/all_focals2.txt', delim='\t', col_names=c("1", "focal", "2", "model"), col_types=cols_only(focal = col_double(), model = col_character())) In…
Emmanuel Touzery
  • 9,008
  • 3
  • 65
  • 81
0
votes
1 answer

Unquoting inside of map2 with tidyeval

I'm creating a function that calculates the number of "runs" or missing or complete data - I want this to work with dplyr::group_by, so I have written this as an S3 method - below is a simplified example of this code. Unfortunately I find that the…
Nick Tierney
  • 192
  • 1
  • 8
0
votes
1 answer

group_by with non-scalar character vectors using tidyeval

Using R 3.2.2 and dplyr 0.7.2 I'm trying to figure out how to effectively use group_by with fields supplied as character vectors. Selecting is easy I can select a field via string like this (function(field) { mpg %>% dplyr::select(field)…
Robin Gertenbach
  • 10,316
  • 3
  • 25
  • 37
0
votes
2 answers

How to implement mutate-like chain evaluation?

Dplyr's mutate function can evaluate "chained" expressions, e.g. library(dplyr) data.frame(a = 1) %>% mutate(b = a + 1, c = b * 2) ## a b c ## 1 1 2 4 How can this be implemented? Quick glance at dplyr's source code reveals the basic…
Tim
  • 7,075
  • 6
  • 29
  • 58
0
votes
1 answer

Create a new variable using dplyr::mutate and pasting two existing variables for user-defined function

I would like to create a function to join the lower and higher bound of confidence intervals (named as CIlow and CIhigh) from a data frame. See the data frame below as…
ungatoverde
  • 161
  • 12
0
votes
0 answers

Difference between `get()` and `UQ()`

I'm trying to use dplyr's group_by() for a variable called (choice) that changes depending on the input given to a Shiny application, and to do that I've been trying to use rlang::UQ(choice). This doesn't work in the manner I'd expect, although it…
RobertMyles
  • 2,673
  • 3
  • 30
  • 45
1 2 3
52
53