verifyInput {utilitiesR}R Documentation

asks a question and waits for valid input.

Description

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.

Usage

  verifyInput(question, ..., extraArgs = list())

Arguments

question

the question to ask the user

...

the list of valid inputs to chose from, of the form input=action. This is the same sort of input that should be fed into switch. All arguments must be names, except possibly one to be used as the default value (which must occur last). See details.

extraArgs

a *list* of extra arguments to pass to the function that gets chosen from .... The format of the list is as for do.call.

Details

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:

The output of this is returned as the output of the function.

Value

the value of one of the elements of ....

Examples

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

[Package utilitiesR version 1.6.2 Index]