Learn R Programming

ratios (version 1.2.0)

check_readline: check_readline

Description

The function checks if a given character string, e.g. value from readline, matches one element of on a given character vector. Without match it keeps asking for a character string by readline until 'q' for quit or a matching string is provided. This is often used to avoid crashing of functions due to wrong input in the options.

Usage

check_readline(x, myletters)

Arguments

x

character vector to be checked, e.g. value from readline

myletters

character vector of entries which should be allowed, e.g. c("yes", "no")

Value

character vector with one of the values given in myletters

Details

Usage is e.g. yesno = check_readline(yesno, c("y", "n") Now the function will make sure that the variable x consists either of "y" or of "n".

See Also

Other sub functions: relError_dataset, select.VarsElements

Examples

Run this code
# NOT RUN {
possibleEntries = c("today", "yesterday")
myEntry = "today"
# or try another entry which is different from "today":
# myEntry = readline("Enter any word (without quotes):   ")
y = check_readline(x = myEntry, myletters = possibleEntries)

# }

Run the code above in your browser using DataLab