2

I am hoping someone can help determine why I receive an error message when using lazy evaluation as part of a dplyr filter_ verb. The end goal is to pass arguments by reference using a function but I have narrowed the problem down outside of a function.

library(dplyr)
library(lazyeval)
library(data.table)

data_raw_dt <- data.table(
  R_dates = seq(from = as.Date("2015/8/31"), by = "1 day", length.out = 30),
  grp_region = sample(letters[1:4], 30, replace = TRUE),
  z_valuation = rnorm(30)
)

# Create some NAs
data_raw_dt$grp_region[data_raw_dt$grp_region == "d"] <- NA

dates = "R_dates"
group = "grp_region"
column = "z_valuation"
filter_criteria = interp(~(!is.na(var)), var = as.name(group))

data_raw_dt %>%
  filter_(filter_criteria)

But this gives the following error message: "Error in lazyeval::common_env(.dots) : argument ".dots" is missing, with no default"

In this case, I am not sure how to specify .dots and when I do it asks for a list. I have checked here, here, and here and structured my code following these examples with no success.

Package version: dplyr 0.4.2 lazyeval 0.1.10 data table 1.9.4

Does anyone have any ideas? Thank you so much in advance!

Community
  • 1
  • 1
Englehas
  • 308
  • 4
  • 9
  • 3
    Please provide a minimal [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Leave off any code that's irrelevant to the error. If none of the variables are actually defined, we can't test the code to see what's wrong. Yry `filter_(.dots=list(filter_criteria))`? – MrFlick Oct 13 '15 at 20:16
  • Include what version of `dplyr` and `lazyeval` you are using from `sessionInfo()` – MrFlick Oct 13 '15 at 20:22
  • @MrFlick thank you, I provided more reproducible code and posted versions of packages. It turns out the problem goes away when I use a data.frame instead of a data.table. Adding data.table to this question. Let me know if I need to do anything else to improve the formatting of this question or it now needs to be deleted/modified since it's a data.table vs. data.frame question. – Englehas Oct 13 '15 at 21:16
  • 2
    If I copy/paste the code above, I do not get any error (`lazyeval_0.1.10`, `dplyr_0.4.3`, `data.table_1.9.6`) – MrFlick Oct 13 '15 at 21:18
  • @MrFlick, thank you again for testing, I will upgrade my R and packages – Englehas Oct 13 '15 at 21:20
  • That did the trick, updating dplyr to 0.4.3 fixed the problem! Thank you for all your help. – Englehas Oct 14 '15 at 17:40

1 Answers1

2

Just replace with

filter_(.dots = filter_criteria)
bramtayl
  • 4,004
  • 2
  • 11
  • 18