Questions tagged [non-standard-evaluation]

156 questions
0
votes
2 answers

Using substitute to robustly capture the input code within glue() in a package

I'm building some utility functions to simplify writing cast(statement as type) in an SQL query easier from R. The way I'm doing so is through one workhorse function, as_type which is called by several one-use functions (e.g. as_bigint); crucially,…
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
0
votes
2 answers

Converting a quoted list into a list of quoted expressions for dplyr::filter

I am writing a function that combines a dplyr::filter step (which I want to parametrize) before doing some other stuff. I want provide a default argument for the filtering criteria that can be overridden. This precludes passing the filtering…
Andrew M
  • 490
  • 5
  • 11
0
votes
0 answers

Vectorised if/else construct to avoid calling expensive function when condition is FALSE?

Background I have a computationally expensive (and SLOW) function which is called from within another function which is part of a dplyr pipeline: dat %>% mutate_at(.vars = vars(dplyr::intersect(starts_with("locale"), ends_with("last_name"))), …
0
votes
2 answers

Mutate multiple columns with conditions using dplyr

I have a large dataset for which I want to create 50 new variables where the values are conditional on values in previous columns, and the name of the variables reflect this fact. To make it more intelligible, here is an example: df <- tibble("a" =…
Jo_
  • 69
  • 6
0
votes
1 answer

group_by and selection helpers / standard evaluation

I'm rewriting some Code in a Project where I need to group by (and summarise) a variablename from a character variable, similar to this: test <- mtcars x <- "gear" This would work with group_by_ the deprecated standard evaluation version of…
snaut
  • 2,261
  • 18
  • 37
0
votes
2 answers

Capturing expressions inside lists as text

I currently have this function, which takes a table and two lists of expressions, and evaluates them, turning them into two matrices. I use two lists instead of ... because I need to be able to determine whether the expressions are going to fall in…
Luiz Rodrigo
  • 936
  • 1
  • 7
  • 19
0
votes
1 answer

R: 'Invalid subscript type symbol'

I am currently working my way through the topics on expressions and quasiquotation in the 2nd edition of Hadley's Advanced R book. In the exercise section 20.6.5 the task is to "Implement arrange_desc(), a variant of dplyr::arrange() that sorts in…
FloHu
  • 1
  • 3
0
votes
1 answer

capturing functions using rlang's enexprs

I'm writing a function such that callers of this function can write schemas declaratively: myschema <- Schema( patientID = character, temp = numeric, treated = logical, reason_treated = factor(levels=c('fever', 'chills', 'nausea')) ) Later,…
daikonradish
  • 682
  • 5
  • 14
0
votes
1 answer

dplyr, rlang: Unable to predict if minor varients of passing names to nested dplyr functions will work

Data for reproducibility .i <- tibble(a=2*1:4+1, b=2*1:4) This function is supposed to take its data and other arguments as unquoted names, find those names in the data, and use them to add a column and filter out the top row. It does not work.…
andrewH
  • 2,281
  • 2
  • 22
  • 32
0
votes
1 answer

non-standard evaluation to update a format with updateInputSlider: bug?

I have a shiny application that has a functionnality to translate its text between several languages, by using some RenderText and an ActionButton to toggle between languages. Here is my app: library(shiny) trads = list(text3=list("text3 in…
agenis
  • 8,069
  • 5
  • 53
  • 102
0
votes
1 answer

Why must local({...}) be defined using two rounds of expression quoting?

I'm trying to understand how R's local function is working. With it, you can open a temporary local scope, which means what happens in local (most notably, variable definitions), stays in local. Only the last value of the block is returned to the…
akraf
  • 2,965
  • 20
  • 44
0
votes
0 answers

ggplot2 non standard evaluation

As I need to use ggplot2 in a function, non standard evaluation mode is required. Therefore, aes_string with "price" is used. However, then ..count.. no longer is defined ggplot(diamonds, aes_string(x="price", ..count../sum(..count..))) +…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
0
votes
0 answers

R, data.table, non-standard evaluation, wrong output names?

First a quick example of what I'm seeing, then some context as to why I'm doing what I'm doing. dt = data.table(i=rep(1:3, each=4), t=rep(1:4, times=3), x=runif(12)) dt[, .(sum=sum(x), cnt=.N), keyby=.(i)] # works as expected # i sum cnt # 1:…
James
  • 630
  • 1
  • 6
  • 15
0
votes
1 answer

How to run nlxb and wrapnls inside dplyr?

I am trying to fit many nonlinear fits using wrapnls in parallel using dplyr and broom (and eventually mclapply), but I am getting a parsing evaluation error from nlxb: Error in parse(text = joe) (from #11) : :1:6: unexpected input 1: b1.10%…
wdkrnls
  • 4,548
  • 7
  • 36
  • 64
0
votes
1 answer

r dplyr non standard evaluation - ordering bar plot in a function

I have read http://dplyr.tidyverse.org/articles/programming.html about non standard evaluation in dplyr but still can't get things to work. plot_column <- "columnA" raw_data %>% group_by(.dots = plot_column) %>% summarise (percentage =…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
1 2 3
10
11