Questions tagged [non-standard-evaluation]
156 questions
1
vote
1 answer
Within a function that uses non-standard evaluation, check whether a column exists
I'm attempting to use non-standard evaluation with a function where one set of things happen if one column is present in the supplied data.frame and something else happens if a different column is present. I don't know how to check that condition,…

shirewoman2
- 1,842
- 4
- 19
- 31
1
vote
1 answer
In R, how do I modify a dataframe column in a list given a string name
I'm new to R. Thank you for your patience. I'm working with the survey package.
Background: I'm writing a function that loops through combinations of predictor and outcome variables (i.e., svyglm(outcome~predictor)) in a complex survey to output…

Trevor C
- 25
- 4
1
vote
1 answer
dplyr non standard evaluation with curly curly outside a function
All the examples i see for curly curly are within the context of writing functions.
I just want to loop around my grouping variables and get frequencies, so i'm trying to get something like this to work:
my_var <- "model"
mpg %>% group_by({{…

chrisjacques
- 635
- 1
- 5
- 17
1
vote
1 answer
R: Tidy eval for base R functions?
I've asked a related question before, but I think this frames it in a more interesting way.
If a base R function is generic, and has one or more arguments that use "standard" nonstandard evaluation, would it be feasible, and if so, would it be…

andrewH
- 2,281
- 2
- 22
- 32
1
vote
1 answer
How to get dplyr::mutate() to work with variable names when called inside a function?
I am exploring data from the Pokemon API (not actually using the API, just pulling the .csv files from the github). In a file that contains the types of every Pokemon in narrow format (a Pokemon can have up to two types) called pokemon_types.csv,…

mkady
- 43
- 5
1
vote
3 answers
Pass variables by name into a function that calls dplyr?
I'm trying to create a function that will take 2 variables from a dataset, and map their distinct values side by side, after which it will write the out to a csv file. I'll be using dplyr's distinct function for getting the unique values.
map_table…

spidermarn
- 959
- 1
- 10
- 18
1
vote
0 answers
R non-standard evaluation : get promise value while leaving it unevaluated [or: keep external pointer valid...]
This a follow-up to Parallelize function taking external pointers (XPtr)
I won't reproduce the Cpp code here to make things shorter. The problem was to that once a parameter of a function is evaluated, it is defined in the function's environment…

Elvis
- 548
- 2
- 14
1
vote
1 answer
How can I specify the name in a name-value pair inside a for loop?
I have this example script:
library(tidyverse)
placeholder <- c("foo", "bar", "baz", "bash")
x <- 1
for (name in placeholder) {
iris <- iris %>% add_column(name = rep("example", nrow(iris)),
.after = x)
x <-…

Nautica
- 2,004
- 1
- 12
- 35
1
vote
2 answers
Dynamic select expression in function
I am trying to write a function that will convert this data frame
library(dplyr)
library(rlang)
library(purrr)
df <- data.frame(obj=c(1,1,2,2,3,3,3,4,4,4),
S1=rep(c("a","b"),length.out=10),PR1=rep(c(3,7),length.out=10),
…

see24
- 1,097
- 10
- 21
1
vote
2 answers
using dplyr::group_by in a function within apply
i'd like to produce nice summaries for a selection of grouping variables in my dataset, where for each group i would show the top 6 frequencies and their associated proportions. I can get this for a single grouping variable using the syntax:
my_db…

chrisjacques
- 635
- 1
- 5
- 17
1
vote
2 answers
R: Non-standard evaluation of dynamic variables within pipes. Replacing (") with (`)
I am attempting to use a dynamic string in a dplyr pipe and a lapply function. Where the string is used to name a column which is later used within a filter. The issue occurs where attempting filter to remove any rows with a resultant NA (using…

Jake Oliver Stephen
- 53
- 6
1
vote
2 answers
How can I pass a variable through a quoted expression into a function that returns a function using that value?
Here's an example:
library(ggplot2)
library(scales) # for percent() function
custom_percent <- function(n){
function(x){
return(paste(percent(x), sprintf('(%d)', round(x* (n)))))
}
}
mydata = data.frame(x = rep(c('a','b','c'),…

Max Candocia
- 4,294
- 35
- 58
1
vote
2 answers
Incorrect evaluation of the parameters of a function using non standard evaluation?
Suppose we have some vectors and dataframes:
a <- c(1, 2, 0, 1)
b <- c(6, 4)
df1 <- data_frame(x = c(6, 8, 12), y = c(24, 18, 16))
We write a function using non standard evaluation that calculates the mean of a column of the dataframe and the mean…

bienqueda
- 89
- 5
1
vote
2 answers
Turn character strings into named function arguments
I have an R script I intend to call from the command line, which includes a function which may take option ... arguments. I'd like to parse any arguments given at the command line as arguments in .... How might I do this?
I've tried the rlang…

Empiromancer
- 3,778
- 1
- 22
- 53
1
vote
1 answer
sparklyr and standard evaluation (SE) based functions
I'm trying to write a function that performs and sdf_pivot() a creates a Spark DataFrame with column names that includes the name of the original variable or column.
set.seed(80)
df <- data.frame(id = c(1:5),
var1 =…

guzu92
- 737
- 1
- 12
- 28