Add an instruction, section, or item to a (pre)registration form

form_add_instruction(x, heading, description, overwrite = TRUE)

form_add_section(x, id, label, description, overwrite = TRUE)

form_add_item(
  x,
  id,
  label,
  description,
  section_id,
  valueTemplate = "string",
  validValues = NA,
  validation = NA,
  overwrite = TRUE
)

Arguments

x

The (pre)registration form as created by form_create().

heading

The instruction's heading

description

The description of the instruction, section, or item

overwrite

Whether to overwrite existing content or append the new content

id

The identifier of the section or item

label

The label (i.e. title) of the section or item

section_id

The section identifier of the section the item should be placed in

valueTemplate

The name of the value template of the item

validValues

The valid values (for categorical items)

validation

The validation statement (an R expression)

Value

The modified (pre)registration form

Examples

### Create an empty example form
exampleForm <-
  preregr::form_create(
    title = "Example form",
    version = "0.1.0"
  ) |>
  preregr::form_show();
#> 
#> ── (Pre)registration form ──────────────────────────────────────────────────────
#> 
#>  Title: Example form
#>  Author: NA
#>  Date: 2023-05-04
#> 
#> ── Instructions ────────────────────────────────────────────────────────────────
#> 
#> ── First instruction ──
#> 
#> Actual instructions
#> 
#> ── Sections and items ──────────────────────────────────────────────────────────
#> 
#> ── Section: Example Section ──
#> 
#>  Example Label [example_item]: Example item description
#> 

### Add some stuff;
exampleForm <-
  exampleForm |>
  preregr::form_add_instruction(
    heading = "First Real Instruction",
    description = "Which normally also contains real instructions here"
  ) |>
  preregr::form_add_section(
    id = "first_section",
    label = "First Real Section",
    description = "This section is very, very important."
  ) |>
  preregr::form_add_section(
    id = "second_section",
    label = "Second Real Section",
    description = "This section is even more important then the first one."
  ) |>
  preregr::form_add_item(
    id = "study_title",
    label = "Study Title",
    section_id = "first_section",
    description = paste0(
      "Think of a catching title, preferably with a colon in ",
      "the middle. Bonus points for pop culture references."
    )
  ) |>
  preregr::form_add_item(
    id = "study_authors",
    label = "Authors",
    section_id = "first_section",
    description = "Maybe list the authors, too."
  ) |>
  preregr::form_add_item(
    id = "registration_type",
    label = "Registration type",
    section_id = "second_section",
    description = paste0(
      "Describe briefly why you are (pre)registering this ",
      "study. For example, this might be a preregistration ",
      "to allow others to know you're doing this study; or to ",
      "make it clear you value transparency in science; or to ",
      "remember your original plans later on. Or this might be ",
      "a registration to update your plans after the data came ",
      "in; or to document pragmatic changes in plans."
    )
  );

### Show the result of our hard labour
preregr::form_show(exampleForm);
#> 
#> ── (Pre)registration form ──────────────────────────────────────────────────────
#> 
#>  Title: Example form
#>  Author: NA
#>  Date: 2023-05-04
#> 
#> ── Instructions ────────────────────────────────────────────────────────────────
#> 
#> ── First Real Instruction ──
#> 
#> Which normally also contains real instructions here
#> 
#> ── Sections and items ──────────────────────────────────────────────────────────
#> 
#> ── Section: First Real Section ──
#> 
#>  Study Title [study_title]: Think of a catching title, preferably with a colon in the middle. Bonus points for pop culture references.
#> 
#>  Authors [study_authors]: Maybe list the authors, too.
#> 
#> 
#> ── Section: Second Real Section ──
#> 
#>  Registration type [registration_type]: Describe briefly why you are (pre)registering this study. For example, this might be a preregistration to allow others to know you're doing this study; or to make it clear you value transparency in science; or to remember your original plans later on. Or this might be a registration to update your plans after the data came in; or to document pragmatic changes in plans.
#>