Learn R Programming

gofigR (version 1.1.3)

read_prompt: Reads a line from stdin with optional validation and retry logic.

Description

This is a small helper used by the GoFigr configuration wizard to collect user input interactively. When a validation function is supplied, the input will be repeatedly requested until it passes validation or the maximum number of attempts is reached.

Usage

read_prompt(prompt, validate = NULL, attempt = 1, max_attempts = 2)

Value

The raw input string, or the result of `validate(input)` if a validation function is supplied.

Arguments

prompt

Character string shown to the user, e.g. "Enter username: ".

validate

Optional function taking a single character argument and either returning a transformed value or throwing an error if the value is invalid.

attempt

Current attempt number (used internally for recursion).

max_attempts

Maximum number of attempts before giving up and throwing an error.