generate_form: Generate form partials

Description Usage Arguments Details Value Functions

View source: R/generate.R

Description

Functions that generate object of class form_partials.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
generate_form(
  prompt = "",
  question = NULL,
  choices = NULL,
  validate = NULL,
  confirm = FALSE,
  pre = NULL,
  post = NULL,
  field_name = "",
  extra_space = " "
)

generate_form_pattern(
  prompt = "",
  question = NULL,
  choices = NULL,
  pattern = "*",
  confirm = FALSE,
  pre = NULL,
  post = NULL,
  field_name = ""
)

generate_form_choices(
  prompt = "",
  question = NULL,
  choices,
  confirm = FALSE,
  pre = NULL,
  post = NULL,
  field_name = ""
)

Arguments

prompt

The string printed when prompting the user for input (see readline()).

question

The question to be asked.

choices

A vector of choices.

validate

A function used to validate the answer (see details), if NULL then validation step is ignored.

confirm

a logical. Should the answer be confirmed (default is FALSE).

pre

A function for pre-processing.

post

A function for post-processing.

field_name

Field name (optional) that will be used in the list of answer.

extra_space

extra space in prompt line.

pattern

pattern to be matched (see grepl().

Details

The object of class form_partial returned is a function with one argument (x) that triggers the following actions once called:

  1. displays a question to be asked (question);

  2. prompts a message (prompt) that is used to specify the nature of the input;

  3. if confirm = TRUE then a confirmation messages will be prompted;

  4. (optional) calls the function pre that transforms the input;

  5. validates the input (validate), i.e. returns TRUE if the input (that may have been transformed) is valid;

  6. (optional) applies a function (post) to the validated input that thereby becomes output

The argument x of a form_partial is set to NULL, it can however be set to a different value. In such case, once the object is called, the interactive steps (the first three steps aforementioned) are skipped and the input goes through the 3 last steps. If the input is not validated then NA will be returned.

Value

A object of class form_partial.

Functions


inSileco/formbuildr documentation built on Jan. 1, 2021, 4:20 a.m.