I am trying to make a function in which I have to provide two arguments. For the first argument, I can enter anything, but for the second only the characters 'A' or 'B' are allowed. Then I wish to return both arguments in a list.
myFunction <- function(var1, var2){
if(missing(var1) | var1 == ""){stop("First argument is missing")}
if(missing(var2) | var2 != "A" | var2 != "B"){stop("Second argument is missing. Accepted values: 'A' or 'B'")}
myList <- list("out1" = var1, "out2"=var2)
return(myList)
}
myFunction("Hello world!", "A")
Error in myFunction("Hello world!", "A") :
Second argument is missing. Accepted values: 'A' or 'B'
What am I missing?