Skip to content

Instantly share code, notes, and snippets.

@thomas-neitmann
Created September 25, 2020 10:51
Show Gist options
  • Save thomas-neitmann/bf703d36b0ca5b5162cf0ba72dbeed73 to your computer and use it in GitHub Desktop.
Save thomas-neitmann/bf703d36b0ca5b5162cf0ba72dbeed73 to your computer and use it in GitHub Desktop.
do_if <- function(data, predicate, expr) {
if (predicate) {
eval.parent(insert_data(
substitute(expr),
substitute(data)
))
} else {
data
}
}
insert_data <- function(expr, data) {
as.call(c(
expr[[1L]],
data,
as.list(expr[-1L])
))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment