上級 › match.arg に候補外の値を渡すと 'arg' should be one of エラーになる › パターン2
match.arg に候補外の値を渡すと 'arg' should be one of エラーになる
match.arg()で選択肢を制限した引数に、定義された候補のどれとも一致しない値を渡すと、'arg' should be one ofというエラーになります。
1 render <- function(format = c("png", "jpg", "svg")) { 2 format <- match.arg(format) 3 cat("format:", format, "\n") 4 } 5 render(_____) ^
'arg' should be one of “png”, “jpg”, “svg”
空欄を埋めて実行を通す
「文字列の引数ならどんな値でも受け取ってくれるはず」という思い込みは誤りで、match.arg()は候補外の値を実行時エラーにします。
次の問題