verifyInput {utilitiesR} | R Documentation |
This is a bit like menu
except it
doesn't display the choices as 1: xx 2: xx
etc.
Suitable for yes/no questions where 'menu' is a bit too
much.
verifyInput(question, ..., case.sensitive = TRUE, extraArgs = list())
question |
the question to ask the user |
... |
the list of valid inputs to chose from, of the
form |
case.sensitive |
whether to coerce all replies to
|
extraArgs |
a *list* of extra arguments to pass to
the function that gets chosen from |
The answer to question
is collected as a string
using readline
.
This is then fed (in string form) to
switch
with the ...
arguments:
switch(readline(question), ...)
.
As such, the default argument (if any) must go last.
The argument that is selected is:
evaluated via do.call(arg, extraArgs)
, if it is a
function.
simply returned, otherwise.
The output of this is returned as the output of the function.
the value of one of the elements of ...
.
## Not run: # example of setting a parameter via a yes/no question: p <- 1 p <- verifyInput(sprintf('current value of p is %i, keep? [Y/N] ', p), Y=, y=p, # return p if they keep N=, n= function() readline('Enter new value for p: ')) # If the user says 'N' they enter a new value for p and this is # returned. ## End(Not run)