What about
myfun <- function(...) which(c(...))
# examples
myfun(TRUE,FALSE,TRUE)
# [1] 1 3
myfun(FALSE,FALSE,TRUE,TRUE,FALSE,TRUE)
# [1] 3 4 6
You can put names in these cases if you want, for example
mystrfun <- function(...) toString(c(letters,LETTERS)[myfun(...)])
mystrfun(TRUE,FALSE,TRUE)
# [1] "a, c"
mystrfun(FALSE,FALSE,TRUE,TRUE,FALSE,TRUE)
# [1] "c, d, f"
Replace with c(letters,LETTERS)any of your desired names and they will be strung together.
Frank source
share