Questions tagged [non-standard-evaluation]
156 questions
1
vote
2 answers
How can I rename an object using Non standard evaluation in R
Context
I have a named vector q1 = 2. The object name is stored in a = 'q1'.
I can change q1's name by names(q1) = 'this_is_name'.
Then I trid to use non standard evaluation to change q1's name.
I thought names(q1) = 'new_name' and names(sym(a)) =…

zhiwei li
- 1,635
- 8
- 26
1
vote
1 answer
How to use non standard evaluation with dollar sign in r
Context
I want to use non-standard evaluation with dollar sign in R.
I want to customize a function with two parameters. data is the input data frame, var is the name of the variable in the input data frame. The return value is the value…

zhiwei li
- 1,635
- 8
- 26
1
vote
3 answers
Non-standard evaluation, R, dplyr
The output below is close to what I want, but not quite. Rather than label being equal to the value of var (e.g. Setosa) I want it to be equal to the name of var (i.e. Species). Seems like a silly thing to do, but hey, it is a reprex.
…

Richard Martin
- 81
- 4
1
vote
1 answer
Trouble with an R function for making a ggplot2 graph and optionally facetting with user-specified columns
I'd like to write a function in R for making some graphs and, optionally, facetting those graphs by whatever column the user inputs. I'd prefer to do this using nonstandard evaluation since I don't know what columns the user will have in the…

shirewoman2
- 1,842
- 4
- 19
- 31
1
vote
3 answers
Non-standard evaluation in dplyr when using dots for variable number of arguments
I am trying to write a function that can be used within a dplyr pipeline. It should take an arbitrary number of columns as arguments, and replace certain substrings in only those columns. Below is a simple example of what I have so…

msm1089
- 1,314
- 1
- 8
- 19
1
vote
2 answers
Tally across columns with variable condition in r
I am trying to tally across columns of a dataframe with values that exceed a corresponding limit variable. Here is a similar problem but for each point, the condition may change so rowSums is not an option. I am interested in either modifications to…

SGE
- 311
- 3
- 10
1
vote
0 answers
Non-standard evaluation with fitting a distribution to truncated data
I would like to create a function that fits a gamma distribution to truncated data.
Let's say I have the following truncated data:
# Simulate some truncated data from gamma distribution
library(truncdist)
library(fitdistrplus)
set.seed(1)
e <-…

mharinga
- 1,708
- 10
- 23
1
vote
1 answer
How to paste parameters in R functions using `substitute` and `eval` to make data.table work like dplyr?
I have a working R function written as:
library(data.table)
mutate_dt = function (.data, ..., by)
{
dt = as.data.table(.data)
substitute(dt[, `:=`(...), by][]) %>% eval()
}
However, I could not use this function in other functions. For…

Hope
- 109
- 5
1
vote
1 answer
R: expss package: Error in do.call(data.frame, c(x, alis)) : variable names are limited to 10000 bytes
I defined some table functions in R using the expss package to automate tabulation.
One of my tables wants to show cases or percentages on categories followed by the mean. The mean can be based on the same category variable or it can be defined to…

michaela stubbers
- 61
- 3
1
vote
2 answers
Using substitute in multiple function calls
foo <- function(arg) {
substitute(arg)
}
foo1 <- function(parm) {
foo(param)
}
foo1(2 + 2)
output is:
param
How can I use substitute inside foo such that the output will be the expression 2 + 2?

Bear Bile Farming is Torture
- 4,317
- 4
- 27
- 61
1
vote
2 answers
In R, how to turn character to verbatim expression?
If I do this:
parse(text="foo()")
I get:
expression(foo())
But what I really need is:
foo()
So basically "foo()" -> foo()
Also, if I try:
as.symbol("foo()")
I get:
`foo()`
I don't want the tick marks

Bear Bile Farming is Torture
- 4,317
- 4
- 27
- 61
1
vote
1 answer
Dynamically create and evaluate function in R
I am trying to dynamically create and evaluate a function from a string input and am hung up, again, on meta-programming/evaluation (https://adv-r.hadley.nz/metaprogramming.html). I have a feeling this is answered on SO, but I searched and wasn't…

maia-sh
- 537
- 4
- 14
1
vote
1 answer
using = inside bquote
a <- "A"
bquote(.(as.name(a)) = 4)
Error: unexpected '=' in "bquote(.(as.name(a)) ="
bquote(A = 4)
Error in bquote(A = 4) : unused argument (A = 4)
a <- "A"
bquote(f(.(as.name(a)) = 4))
Error: unexpected '=' in "bquote(f(.(as.name(a)) ="
How can…

Bear Bile Farming is Torture
- 4,317
- 4
- 27
- 61
1
vote
1 answer
Passing column name into function
I have a simple problem with non-standard evaluation: passing a variable name as an argument into a function.
As a reproducible example, here's a simple thing: taking the mean of one variable, mpg from the mtcars dataset. My end goal is to have a…

Jeremy K.
- 1,710
- 14
- 35
1
vote
2 answers
Pass column of data frame to inner function
I would like to pipe in columns into a function that performs a purrr::imap_dfr with a custom inner function.
My goal is df %>% diffmean(df, group, col1, col2) would run t.test(col1 ~ group, .data = df) and t.test(col2 ~ group, .data = df.
ttests <-…

Dylan Russell
- 936
- 1
- 10
- 29