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

dplyr programming: unquote-splicing causes overscope error with complete() and nesting()

So I've started to dip my toes into the wonderful world of dplyr programming. I'm trying to write a function that accepts a data.frame, a target column, and any number of grouping columns (using bare names for all columns). The function will then…
Brain_Food
  • 718
  • 1
  • 7
  • 17
3
votes
1 answer

Splice a quosure and format into a list of strings

The by argument in dplyr::left_join (and friends) expects a list of strings. My code already defines the variables of interest as a list of quosures so I want to avoid writing the list down a second time by converting the list of quosures to a list…
Stanwood
  • 268
  • 1
  • 10
3
votes
4 answers

Getting filter within a function to work with tidy evaluation

I'm trying to use dplyr to filter based on a dynamic variable. I've figured out that to get filter to work, I need to enclose the variable name in parentheses. However, if I program this into a fuction, it does not work properly. df_ex <-…
matsuo_basho
  • 2,833
  • 8
  • 26
  • 47
3
votes
2 answers

R dplyr operate on a column known only by its string name

I am wrestling with programming using dplyr in R to operate on columns of a data frame that are only known by their string names. I know there was recently an update to dplyr to support quosures and the like and I've reviewed what I think are the…
bmosov01
  • 589
  • 5
  • 15
3
votes
1 answer

concatenate quosures and string

I'm looking for a way to concatenate a quosure and a string whose result is a quosure. Actually, if I use paste0() and quo_name(), I can do it. But I wonder if there is a more elegant alternative to write a function in my package. This is a generic…
Italo Cegatta
  • 410
  • 4
  • 8
3
votes
3 answers

Writing own function using dplyr and group_by - how to continue with changed column names

I would like to make tables for publication that give the number of observations, grouped by two variables. The code for this works fine. However, I have run into problems when trying to turn this into a function. I am using dplyr_0.7.2 Example…
eve
  • 33
  • 3
3
votes
2 answers

Using pre-existing character vectors in quasiquotation of an expression with rlang

Sometimes when working with dplyr one has a character vector of column names that's to be used to operate on data, for instance: cols_of_interest <- c("Petal.Width", "Petal.Length") In dplyr 0.5.0 and earlier, the recommended approach to this…
2
votes
3 answers

How to create new variables based on an external named list/vector of computations dplyr

Imagine I want to do the following operation: library(dplyr) mtcars %>% group_by(x = am) %>% summarize(y = sum(vs), q = sum(mpg), p = sum(mpg/vs)) which yields: #> # A tibble: 2 × 4 #> x y q …
2
votes
1 answer

Build a dynamic-dots list to read dataframe one row at a time

I am trying to build a GET request one row at a time from a dataframe where the possible parameters are a varied and large list, and the dataframe I'm passing to the function may not have the correctly named column headers. SAMPLE STARTING…
ScottyJ
  • 945
  • 11
  • 16
2
votes
2 answers

simplify list with name/value pairs in R

I have a list of lists, each of them with format like the following: list( name = 'foo', type = 'bar', attributes= list( list(name='color', value='blue' ), list(name='batch', value=123), …
Yuriy Barvinchenko
  • 1,465
  • 1
  • 12
  • 17
2
votes
1 answer

Write function that access data from dplyr context

Disclaimer: this is a very elemental question. I'll use an example to make it easier, but the question has nothing to do with the example itself. Supose you have a dataframe df: # A tibble: 5 × 4 index a b c 1…
2
votes
1 answer

unquote a param upon passing to function using eval(substitute())

Suppose I have a simple function that uses eval(substitue) with an object of class data.table: f <- function(df,col) eval(substitute(df[,mean(col)])) If I then have a simple data.table (d), with columns b1 and b2, I can call this function f(), as…
langtang
  • 22,248
  • 1
  • 12
  • 27
2
votes
1 answer

Extract input column names from dplyr mutate

Is there a way to extract the input column names from the mutate function? Given any expressions, I ideally want an output telling me which columns were affected by the mutate call. For example, I'm supplying a few tidy-based expressions to mutate…
NicChr
  • 858
  • 1
  • 9
2
votes
0 answers

R Package Developement, How to find devtools test() full stack of warning backtraces?

I am working on creating a package for the first time with roxygen2 and so far the project is coming along way. However, I noticed that I cannot seem to get the same layer of warning outputs in my console as with the devtools::test() package. To…
Ookami
  • 21
  • 1
2
votes
1 answer

Apply a list of functions to a data frame

I have this data frame test <- data.frame( a = c(1, "two", "na", 4), b = c(1, 2, 3, 4), c = c(1, "nA", 3, 4), d = c("na", NA, TRUE, "5*"), e = c(3, 4, 0.02,…
anria
  • 37
  • 4