Last active
March 13, 2024 13:59
-
-
Save alekrutkowski/ff5446fa709d42d50c5e975123c1bf40 to your computer and use it in GitHub Desktop.
R function for dealing with (ignoring) missing/empty arguments inside ellipsis (...)
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
listWithoutEmptyArgs <- function(...) | |
eval(Filter(\(x) !identical(as.character(x), "") || identical(x,""), | |
bquote(.(substitute(list(...)))))) | |
# > list(a=1,,b=2:10) | |
# Error in list(a = 1, , b = 2:10) : argument 2 is empty | |
# > listWithoutEmptyArgs(a=1,,b=2:10) | |
# list(a = 1, b = 2:10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
N.B.
list
is the most universal/general native structure in R, which you can convert to more specialized data structures with e.g.as.data.frame
oras.data.table
or use for calling function withdo.call
.