Package 'formbuildr'

Title: Form builder
Description: Build forms with the command line interface.
Authors: Kevin Cazelles [aut, cre] , Nicolas Casajus [aut]
Maintainer: Kevin Cazelles <[email protected]>
License: GPL-3
Version: 0.0.0.9000
Built: 2024-11-16 04:19:52 UTC
Source: https://github.com/inSileco/formbuildr

Help Index


Export answers.

Description

Export answers.

Usage

export_answer(x, file, format = "yaml")

Arguments

x

object of class form_answers.

file

file name.

format

So far only YAML is available.


A binary question to be answered by Yes or No.

Description

A binary question to be answered by Yes or No.

Usage

fob_among(question, choices, field_name = "", output = "choice", ...)

fob_month(question, field_name = "", output = c("choice", "id"), ...)

fob_weekday(question, field_name = "", output = c("choice", "id"), ...)

Arguments

question

The question to be asked.

choices

A vector of choices.

field_name

Name of the field (optional).

output

Either "choice" or "id".

...

further arguments to be passed to generate_form_choices().

Value

Return the choice selected either as the choice value or its identifier (an integer).

Functions

  • fob_month: One month.

  • fob_weekday: One weekday.


Generate any kind of question.

Description

Generate any kind of question.

Usage

fob_any(type, ...)

Arguments

type

Type of answer expected.

...

Further arguments passed to the question function.


Generate one question.

Description

Generate one question.

Usage

fob_int(question, field_name = "", prompt = NULL)

fob_num(question, field_name = "", prompt = NULL)

fob_date(question, field_name = "", format = "%Y-%m-%d", prompt = NULL, ...)

fob_char(question, field_name = "", prompt = NULL)

fob_yorn(question, field_name = "", prompt = "Enter [Y]es or [N]o:", ...)

fob_bool(question, field_name = "", prompt = "Enter [T]RUE or [F]ALSE:", ...)

Arguments

question

The question to be asked.

field_name

Name of the field (optional).

prompt

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

format

Date format.

...

Further arguments to be passed to generate_form_pattern().

Value

one integer.

Functions

  • fob_num: one numeric.

  • fob_date: one date.

  • fob_char: a character.

  • fob_yorn: TRUE for yes and FALSE for no.

  • fob_bool: one boolean/logical (i.e. TRUE or FALSE).


Add an output.

Description

Add an output.

Usage

fob_output(FUN, field_name = NULL)

Arguments

FUN

a function a character string that will be displayed.

field_name

Field name.

Value

An object of class output.


A binary question to be answered by Yes or No.

Description

A binary question to be answered by Yes or No.

Usage

fob_pattern(
  question,
  pattern,
  field_name = "",
  prompt = "Enter your answer:",
  ...
)

Arguments

question

The question to be asked.

pattern

Pattern to be matched.

field_name

Name of the field (optional).

prompt

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

...

Further arguments passed to generate_form_pattern().

Value

answer validated.


Add a section.

Description

Add a section.

Usage

fob_section(msg)

Arguments

msg

a character string that will be displayed.

Value

A section object.


A binary question to be answered by Yes or No.

Description

A binary question to be answered by Yes or No.

Usage

fob_word(question, field_name = "", prompt = NULL, ...)

fob_text(question, field_name = "", max = NULL, prompt = NULL, ...)

fob_email(question, field_name = "", prompt = NULL, ...)

Arguments

question

The question to be asked.

field_name

Name of the field (optional).

prompt

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

...

further arguments to be passed to generate_form_pattern().

max

maximum of characters (ignored if NULL).

Value

a word.

Functions

  • fob_text: a character string.

  • fob_email: a character string.


Create a form from a connection.

Description

Create a form from a connection.

Usage

form_from_file(con)

Arguments

con

a connection object or a character string (see readLines()).

Details

This function reas

  • ⁠q:⁠ question

  • ⁠t:⁠ type

  • ⁠p:⁠ prompt message (optional)

  • ⁠f:⁠ field name (optional)

  • ⁠#'⁠ a section


Generate form partials

Description

Functions that generate object of class form_partials.

Usage

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

  • generate_form_pattern: match pattern.

  • generate_form_choices: list fo choices.


objects of class form_partial or form

Description

objects of class form_partial or form

Usage

join(...)

x %+% y

Arguments

...

object(s) of class form_partial, form, section or output.

x, y

objects of class form_partial, form, section or output.

Value

A form.

Functions

  • %+%: join operator.


Repeat a form.

Description

Fill out the same form by multiple participants.

Usage

multi(x, n = 1, names = NULL)

Arguments

x

a object of class form.

n

number of participants.

names

participants names.