Luke Hartigan
2014-Jul-25 12:22 UTC
R function returning a list of variable(s) conditional on the value of an option?
Dear all,
I have an R function which returns a list of variables; however, within the
body of the function I would like to incorporate a branch based on a user
selected option that will mean there will be one different variable to
return based on the option value.
I was thinking of doing something like this (only an example):
foo <- function(x, y, option = TRUE)
{
.
If (option == TRUE) {
z = z
} else {
w = w
}
return(list(x = x, y = y, z = ifelse(option == TRUE, z, NA), w ifelse(option !=
TRUE, w, NA))
}
However, I was wondering if anyone else had a better idea/method which might
be more elegant?
Many thanks,
Luke
[[alternative HTML version deleted]]