In one comment to the accepted answer on how to \"correctly\" specify optional arguments in R, @LouisMaddox said
missing()
is useless when y
If you have a small number of options then use match.arg
within the function. See ?match.arg
for an example.
If the valid argument is all one letter strings then you will need to another approach such as:
# returns logical
is_one_letter_string <- function(x) {
!missing(x) && length(x) == 1 && is.character(x) && x %in% c(letters, LETTERS)
}