Questions tagged [non-standard-evaluation]
156 questions
3
votes
1 answer
Is there delayed set in Julia? (equivalent of := from Mathematica)
I want to call something like rand((0, 1), N) (with N some integer assigned previously) many times in different parts of a program (all occurrences of which I might change in the future to, for example, rand((-1, 1), N) or randn(N)). How can I…

Grayscale
- 1,462
- 1
- 13
- 20
3
votes
2 answers
How to call `eval` with `with` function?
Having an lm object I need to create a function based on its variables represented as character vector. I have tried to use a combination of eval and expr to create an f function that would be further used in obj and nlm optimisation of the…

Xaume
- 293
- 2
- 16
3
votes
2 answers
Order by multiple columns using non-standard evaluation
Let's say I want to order a data.frame using multiple columns and using non-standard evolution. I might have a function that looks something like this
my_order <- function(data, ...) {
with(data, order(...))
}
I get an error when I use this…

nathaneastwood
- 3,664
- 24
- 41
3
votes
1 answer
R - Checking if a string is a valid mathematical expression using non-standard evaluation
I would like to check if the strings below are valid mathematical expressions:
s1 = 'sin(x)'
s2 = 'sin(x*m)'
s3 = 'sin'
s4 = 'sin(xm)'
By 'valid', I mean the expression is a combination of
operators (must be used in conjunction with variables or…

user51462
- 1,658
- 2
- 13
- 41
3
votes
1 answer
Understanding scope with non-standard evaluations in R data.table
How can I ensure that my nonstandard evaluation1 using data.table is inheriting the variables it needs from the parent frame?
Based on my understanding of dynamic scope, my code below should work, but it doesn't. What am I doing wrong?
Details
I…

C8H10N4O2
- 18,312
- 8
- 98
- 134
3
votes
2 answers
Making informative `stopifnot()` errors using NSE in R
I want to make informative stopifnot() errors.
I've read:
http://r-pkgs.had.co.nz/tests.html (the section at the end on using NSE to make informative test error print out for the example seems relevant)
and…
user7613376
2
votes
2 answers
avoid repeated unquoting in dplyr non standard evaluation
Suppose we have the following data:
tib <- tibble::tibble(x = 1:10)
Then, suppose we want to make a function that takes a column as input and returns a tibble with several added columns such as:
library(dplyr)
generate_transformations <-…

Baraliuh
- 2,009
- 5
- 11
2
votes
2 answers
How to use tidyeval in base function in r
I wrote a function.
In my function, there is a step that needs to extract the number of non-repeating values, similar to this:
df = data.frame(a = c(1, 1:3))
df
length(unique(df$a))
> length(unique(df$a))
[1] 3
I use tidyeval for programming,…

zhiwei li
- 1,635
- 8
- 26
2
votes
1 answer
How to pass a variable to a function which has already implement non-standard evaluation in its argument in R?
I am trying to wrap up a function from an R package. From the source codes, it appears that it has non-standard evaluations for some arguments. How can I write my function to pass the value to the argument that has non-standard evaluation…

Fred
- 579
- 2
- 4
- 13
2
votes
1 answer
Passing column names as dot-dot-dot for non-standard evaluation on qplot()
I thought of a lovely use case for map + ... for a purrr workshop: splitting a data.frame into a list of data.frames and then plot them individually through a qplot(...) call.
groups_of_plots <- function(data, group, ...){
table_list <-…

pheymanss
- 152
- 7
2
votes
4 answers
Loop over character vectors and use elements as column names within lambda function
I would like to loop over a vector of variable names with purrr, then use the variables inside a function with dplyr, as with the following code:
library(dplyr)
library(purrr)
#creating index
index<-c('Sepal.Length', 'Sepal.Width')
#mapping over…

GuedesBF
- 8,409
- 5
- 19
- 37
2
votes
2 answers
in R, how do I quote a comment using quote or bquote?
quote(# this is a comment)
How can I do something like the above?

Bear Bile Farming is Torture
- 4,317
- 4
- 27
- 61
2
votes
2 answers
Using `facet_wrap` in a function with non-standard evaluation with vector valued arguments
I want to make a function that uses ggplot and facet_wrap and passes the function variables to facet by.
I can do the following using quoted arguments.
library(tidyverse)
my_grid_plot <- function(facet_by){
ggplot(mtcars, aes(wt, disp)) +
…

mjandrews
- 2,392
- 4
- 22
- 39
2
votes
2 answers
Assigning labels to a data frame from bank of possible labels
I would like to create a function that updates a data frame from a different environment. Specifically, I would like to update the labels of a data frame using the Hmisc::label() function.
assign_label <- function(df, col) {
col <-…

Dylan Russell
- 936
- 1
- 10
- 29
2
votes
4 answers
Use NSE to construct a formula
I am trying to construct a formula using NSE so that I can easily pipe in columns. The following is my desired use case:
df %>% make_formula(col1, col2, col3)
[1] "col1 ~ col2 + col3"
I have made first this function:
varstring <- function(...) {
…

Dylan Russell
- 936
- 1
- 10
- 29