Last active
March 31, 2018 12:23
-
-
Save gshotwell/48cebca44f6903e86503a1709f1ac65d to your computer and use it in GitHub Desktop.
Flexi-add
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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