Skip to content

Instantly share code, notes, and snippets.

@bfatemi
Last active February 14, 2021 22:29
Show Gist options
  • Save bfatemi/e099776e28c24eaa696f8b20c5afd8ac to your computer and use it in GitHub Desktop.
Save bfatemi/e099776e28c24eaa696f8b20c5afd8ac to your computer and use it in GitHub Desktop.
###
### Scenario Index Table
###
..AND <- function(..., .env = rlang::caller_env()){
dd <- pryr::dots(...)
Reduce("&", lapply(dd, eval, envir = .env))
}
..OR <- function(..., .env = rlang::caller_env()){
dd <- pryr::dots(...)
Reduce("|", lapply(dd, eval, envir = .env))
}
dt <- data.table::as.data.table(iris)
data.table::setnames(dt, letters[1:5])
dt[..AND(a > 5, b > 3, c*d <= .3)]
dt[ ..OR(a > 5, b > 3, c*d <= .3)]
..AND(a > 5, b > 3, c*d <= .3, .env = dt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment