i writing function accepts inputs (in example "a" , "b"). other inputs function return error.
test <- function(x) { allowedx <- c("a","b") if(x %in% allowedx) print("good choice!") else stop("wrong input!") }
to users of function supply allowed values x (stored in allowedx) using tab completion feature in r , replace default file name completion typically applied after quote. pressing tab should give like:
test(x="<tab> b
however, couldn't find solution far how map vector allowedx tab completion in r. can tell me how that?
thanks in advance!
you try following:
test <- function() { allowedx <- c("a","b") x = readline('please enter choice of parameters (either "a" or "b"): ') if(x %in% allowedx) print("good choice!") else stop("wrong input!") }
Comments
Post a Comment