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

rlang and enquo does not work inside brackets

I am trying to write a function that operates on a data.frame and will accept dplyr-style arguments, i.e. column names that are not quoted by using dplyr's pronous (or whatever we call it). But I have encountered a problem when using !! inside a…
MrGumble
  • 5,631
  • 1
  • 18
  • 33
0
votes
1 answer

select_ in dplyr returns exception

I am facing the following exception: library(tidyverse) library(dplyr) library(rlang) data(mtcars) select_expr = "mpg , cyl" mtcars %>% select_(select_expr) Error in parse(text = x): :1:5: unexpected ',' 1: mpg , ^ What I am doing…
user8270077
  • 4,621
  • 17
  • 75
  • 140
0
votes
1 answer

Custom ML function not working: undefined columns selected

I am trying to write a custom function to do logistic regression-based ML with the caTools package, but I keep getting the error: undefined columns selected. I checked the input to xlearn and ylearn arguments to the logit_boost function and, as…
Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51
0
votes
0 answers

R ggplot - "Error in is_list(x) : object 'rlang_is_list' not found"

I have some code from a couple of weeks ago that uses ggplot and was working without any problems. Now when I try to run the even one layer of the multi-level plot function, I get an error. I have a dataframe that looks like this excerpt: X…
Conner M.
  • 1,954
  • 3
  • 19
  • 29
0
votes
1 answer

rlang: refer var in the tidyr unite function

Here is my data: df <- tibble::tribble( ~A, ~B, ~C, "a", "b", 2L, "a", "b", 4L, "c", "d", 3L, "c", "d", 5L ) var <- "AB" I want to get this output: df1 <- df %>% unite("AB", c("A", "B")) %>% group_by(AB) %>% nest() However,…
Geet
  • 2,515
  • 2
  • 19
  • 42
0
votes
2 answers

Capturing expressions inside lists as text

I currently have this function, which takes a table and two lists of expressions, and evaluates them, turning them into two matrices. I use two lists instead of ... because I need to be able to determine whether the expressions are going to fall in…
Luiz Rodrigo
  • 936
  • 1
  • 7
  • 19
0
votes
1 answer

Failing to install Kieran Healy's 'socviz' package from github using devtools

I am trying to follow along with the online data viz resource by Kieran Healy (socviz.co), and have had minimal trouble setting things up to do so. I cannot seem to successfully install his 'socviz' package. This is the code Healy…
0
votes
1 answer

Using string with special characters with quo(), in rlang package

I have two variables, a and b. I try to compute a-b using expression with the rlang package. quo(a-b) returns, as expected: ~a - b However, I have a and b as strings. So I tried: quo(!!sym("a-b")), which results in
Rtist
  • 3,825
  • 2
  • 31
  • 40
0
votes
1 answer

capturing functions using rlang's enexprs

I'm writing a function such that callers of this function can write schemas declaratively: myschema <- Schema( patientID = character, temp = numeric, treated = logical, reason_treated = factor(levels=c('fever', 'chills', 'nausea')) ) Later,…
daikonradish
  • 682
  • 5
  • 14
0
votes
1 answer

Dplyr function with optional default argument and required ellipiss

I've a simple function that adds counts for unique combination of variables: Function # Add tally summary for group add_tally <- function(df, n = "n", ...) { # Grpup variables group_vars <- rlang::quos(...) # Check if ellipsis is empty if…
Konrad
  • 17,740
  • 16
  • 106
  • 167
0
votes
1 answer

Parsing a formula

I have the following function, gigl, where I am trying to capture the variables on the left and right of |. Currently my code only captures the variables if it is named exactly s or n. How can I generalize the following to evaluate any variable…
Alex
  • 2,603
  • 4
  • 40
  • 73
0
votes
3 answers

Making new expressions within a function using existing quosures (dplyr programming)

I am trying to make "new expressions" based off quosures within a function from its arguments, but am unsure of how exactly to make this new expression. Here is an example where I pass a numerator and denominator and would ideally do mutations on…
Andy
  • 4,549
  • 31
  • 26
0
votes
1 answer

custom function not accepting arguments with rlang::enquo

I am writing a custom function which requires creating a data frame out of entered arguments. I want users to allow two different way to enter the arguments. As you can see below, one of the way is working, but not the one relying on rlang. The idea…
Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51
0
votes
1 answer

Function that captures the elements of a list and uses them as names to create a list-column data frame

I have the following data frames d1 <- tibble(condition = c("a", "b"), x = c(1, 1)) %>% group_by(condition) d2 <- tibble(condition = c("a", "b"), y = c(2, 2)) %>% group_by(condition) d3 <- tibble(condition = c("a", "b"), z = c(3, 3)) %>%…
danilinares
  • 1,172
  • 1
  • 9
  • 28
0
votes
1 answer

Dplyr conditional column ifelse with vector input

I am trying to use dplyr's new NSE language approach to create a conditional mutate, using a vector input. Where I am having trouble is setting the column equal to itself, see mwe below: df <- data.frame("Name" = c(rep("A", 3), rep("B", 3), rep("C",…
Nick
  • 3,262
  • 30
  • 44