Skip to content

Instantly share code, notes, and snippets.

@gshotwell
Last active March 31, 2018 12:23
Show Gist options
  • Save gshotwell/48cebca44f6903e86503a1709f1ac65d to your computer and use it in GitHub Desktop.
Save gshotwell/48cebca44f6903e86503a1709f1ac65d to your computer and use it in GitHub Desktop.
Flexi-add
library(tidyverse)
add <- function(...){
args <- eval(substitute(alist(...)))
args <- replaceMissingWithZero(args)
args %>% purrr::reduce(sum)
}
replaceMissingWithZero <- function(l){
out <- lapply(l, function(x){
if (rlang::is_missing(x)) {
return(0)
} else {
return(eval(x))
}
})
return(out)
}
add(1, ,3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment