Skip to content

Instantly share code, notes, and snippets.

@mpjdem
Created August 30, 2019 08:09
Show Gist options
  • Save mpjdem/fc28275a7a8047df2c1f00a94c7fe834 to your computer and use it in GitHub Desktop.
Save mpjdem/fc28275a7a8047df2c1f00a94c7fe834 to your computer and use it in GitHub Desktop.
'Command' design pattern in R
compose_quote <- function(body_part, creature_name) {
cat(paste0("Go for the ", body_part, ", ", creature_name, "!\n"))
}
execute <- function(fn, ...) {
Sys.sleep(1)
fn(...)
# Or: do.call(fn, list(...))
# Or: rlang::exec(fn, ...)
}
execute(compose_quote, "eyes", "Boo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment