R Proper checking of supplied parameters against a list of values?

后端 未结 1 1261
余生分开走
余生分开走 2021-01-23 10:14

In one comment to the accepted answer on how to \"correctly\" specify optional arguments in R, @LouisMaddox said

missing() is useless when y

1条回答
  •  醉梦人生
    2021-01-23 10:33

    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)
    }
    

    0 讨论(0)
提交回复
热议问题