Questions tagged [non-standard-evaluation]

156 questions
5
votes
1 answer

How can I define an S3 method for an unevaluated assignment expression?

tl;dr: R CMD check complains when I implement a generic for the S3 class <-, because it thinks that the function is a replacement function with incorrect arguments. I need to define a set of S3 generics to walk an AST of unevaluated R…
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
5
votes
3 answers

curly curly tidy evaluation programming with multiple inputs and custom function across columns

My question is similar to this question but I need to apply a more complex function across columns and I can't figure out how to apply Lionel's suggested solution to a custom function with a scoped verb like filter_at() or a filter()+across()…
lost
  • 1,483
  • 1
  • 11
  • 19
5
votes
1 answer

How to pass "everything possible" to by in a function?

I am trying to use data.table within a user facing function in a package I'm working on. I would like this function to behave as data.table-like as possible. This means for example that my function also features a by argument, which is passed to the…
der_grund
  • 1,898
  • 20
  • 36
5
votes
1 answer

Repeatedly mutate variable using dplyr and purrr

I'm self-taught in R and this is my first StackOverflow question. I apologize if this is an obvious issue; please be kind. Short Version of my Question I wrote a custom function to calculate the percent change in a variable year over year. I would…
Sean Williams
  • 55
  • 1
  • 6
4
votes
3 answers

Is it possible to get the original symbol name from an internally-called function?

I suspect that the answer is "No, you have to make a standard evaluation escape hatch", but maybe someone has some ideas. Imagine writing a function that use non-standard evaluation to get the symbol/name of an object passed into it: inner_func <-…
DuckPyjamas
  • 1,539
  • 13
  • 17
4
votes
3 answers

How to use an expression in dplyr::mutate in R

I want to add a new column based on a given character vector. For example, in the example below, I want to add column d defined in expr: library(magrittr) data <- tibble::tibble( a = c(1, 2), b = c(3, 4) ) expr <- "d = a + b" just as…
Koopa
  • 77
  • 3
4
votes
2 answers

How to pass everything possible to i, j and by in nested functions?

I'm working on a package which uses data.table inside. In this package, I have a function count_by which calculates the number of distinct ID's for a specific variable in a data.table by groups. With some help (R data.table: How to pass "everything…
der_grund
  • 1,898
  • 20
  • 36
4
votes
0 answers

How to find *all* lexically referenced variables hidden inside of functions?

I am trying to extract out all symbols inside the body of a function which were not defined in that function, but which were defined somewhere up the environment stack. I originally thought that I could do this using the return value of…
wdkrnls
  • 4,548
  • 7
  • 36
  • 64
4
votes
1 answer

Partially evaluate expression when doing non-standard evaluation in R

I'm digging my head into R's non-standard evaluation mechanisms. Halfway there, I'm still stuck from time to time. ;-) I made a little calculator that pretty-prints the calculation together with the result: calculator <- function(e)…
symbolrush
  • 7,123
  • 1
  • 39
  • 67
4
votes
2 answers

Non-standard evaluation and quasiquotation in dplyr() not working as (naively) expected

I am trying to search a database and then label the ouput with a name derived from the original search, "derived_name" in the reproducible example below. I am using a dplyr pipe %>%, and I am having trouble with quasiquotation and/or non-standard…
Josh
  • 1,210
  • 12
  • 30
4
votes
2 answers

Select named [list] element using tidy evaluation

I'm trying to wrap my head around non-standard evaluation as it's interpreted in the rlang package. With that goal in mind, my question is: How do I write a dplyr::select.list() function that is consistent with tidy evaluation principles? Here's…
mkearney
  • 1,266
  • 10
  • 18
3
votes
2 answers

Is it possible to substitute into `i` element in data.table[i, j , by]

I'm wondering if it's possible to substitute expressions into the i portion of data.table. I've set up a deeply nested list that contains preset parameters to perform subsetting depending on which sub-group a user has selected in a shiny app. I'm…
Jamie
  • 1,793
  • 6
  • 16
3
votes
3 answers

Concisely assign vector output of a function to multiple variables in dplyr

I am trying to assign the vector output (i.e. greater than length 1) of a function to multiple columns in a single operation (or at least as concisely as possible). Take the range() function for example which returns as output a numeric vector of…
henhesu
  • 756
  • 4
  • 9
3
votes
1 answer

canonical NSE differentiation between names and expressions

Is there a canonical base-R method to determine if a function argument is an object name vice a literal/expression? While NSE is typically discouraged, occasionally somebody has a good idea and wants to use it. The simplest use-case that I might…
r2evans
  • 141,215
  • 6
  • 77
  • 149
3
votes
2 answers

How to get the name of variable in NSE with dplyr

So I've found many times various different ways to achieve this, but as of the past year or so there have been changes to the way dplyr handles non standard evaluation. Essentially one way to achieve this is as follows: require("dplyr") test <-…
JoeTheShmoe
  • 433
  • 6
  • 13
1
2
3
10 11