0
library(dplyr)

specials <- names(mtcars)[1:2]
specials[1]

i=1

setup is complete, this works...

mtcars %>%
  select_(specials[i], ~gear, ~carb)

why does the nse fail on adding the filter?

mtcars %>%
  select_(specials[i], ~gear, ~carb) %>%
  filter_(specials[i] == 21.4)
ben_says
  • 2,433
  • 4
  • 17
  • 18

1 Answers1

1

We may need the interp

library(lazyeval)
library(dplyr)
mtcars %>%
      select_(specials[i], ~gear, ~carb) %>% 
      filter_(interp(~nm == 21.4, nm = as.name(specials[1])))
#  mpg gear carb
#1 21.4    3    1
#2 21.4    4    2
akrun
  • 874,273
  • 37
  • 540
  • 662
  • 3
    To elaborate on the answer, `special[i]` has the value "mpg" and `"mpg" == 21.4` is not true. Hence, the failure. `filter_` evaluates boolean expressions, so we have to construct an expression that uses `mpg` as a column-name. `lazyeval::interp` provides a way to plug values into expressions. – TJ Mahr Aug 31 '16 at 19:52