This function inserts a (pre)registration form, or one or more sections, into an R Markdown file.

form_knit(x, section = NULL, headingLevel = 2)

Arguments

x

The (pre)registration form (as produced by a call to form_create()) or initialized preregr object (as produced by a call to prereg_initialize()).

section

The section(s) to show; pass NULL (the default) to show everything.

headingLevel

The level to use for the top-most heading.

Value

x, invisibly

Examples

preregr::form_create(
  title = "Example form",
  version = "0.1.0"
) |>
  preregr::form_knit();
#> No viewer found, probably documenting or testing
#> 
#> 
#> <style>
#> .preregr {
#> }
#> .preregr-item-spec {
#>   padding: 5px;
#> }
#> .preregr-form-item-spec {
#>   padding: 5px;
#> }
#> .preregr-unspecified {
#>   background-color: #FDFAF2;
#>   color: #F0C566;
#> }
#> .preregr-specified {
#>   background-color: #F2FAF8;
#> }
#> .preregr-item-heading {
#>   display: block;
#> }
#> .preregr-item-label {
#>   font-weight: bold;
#>   display: inline; 
#>   color: black;
#> }
#> .preregr-item-id {
#>   display: inline;
#>   float: right;
#>   font-family: monospace;
#>   color: black;
#> }
#> .preregr-item-spec-text {
#> }
#> </style>
#> 
#> <div style="display:block;clear:both;" class="preregr-spec-start"></div>
#> <div class="preregr-spec-container preregr-spec-full">
#> 
#> 
#> 
#> 
#> 
#> ## Example form {#preregr-form-3dnOkLjZB0}
#> 
#> 
#> 
#> 
#> 
#> ### Instructions
#> 
#> 
#> 
#> #### First instruction {#preregr-form-GPwOE9Sb5C}
#> 
#> 
#> 
#> Actual instructions
#> 
#> 
#> 
#> 
#> 
#> ### Sections and items
#> 
#> 
#> 
#> #### Section: Example Section {#preregr-form-teRNmCzk1g}
#> 
#> <div class="preregr preregr-form-item-spec preregr-form-item">
#> <div class="preregr-item-heading">
#> <div class="preregr-item-label">Example Label</div>
#> <div class="preregr-item-id">example_item</div>
#> </div>
#> <div class="preregr-item-spec-text">Example item description</div>
#> </div>
#> 
#> 
#> 
#> 
#> </div>
#> <div style="display:block;clear:both;" class="preregr-spec-end"></div>
#> 
#> 
#> 
#> <div id="preregr-data-ZB8DXkJTe1" class="preregr preregr-json" data-preregr='{
#>   "form": {
#>     "instructions": {
#>       "First instruction": {
#>         "heading": ["First instruction"],
#>         "description": ["Actual instructions"]
#>       }
#>     },
#>     "metadata": {
#>       "title": {
#>         "field": ["title"],
#>         "contents": ["Example form"]
#>       },
#>       "version": {
#>         "field": ["version"],
#>         "contents": ["0.1.0"]
#>       },
#>       "author": {
#>         "field": ["author"],
#>         "contents": [null]
#>       },
#>       "date": {
#>         "field": ["date"],
#>         "contents": ["2023-05-04"]
#>       }
#>     },
#>     "items": {
#>       "example_item": {
#>         "section_id": ["example_section"],
#>         "item_id": ["example_item"],
#>         "item_label": ["Example Label"],
#>         "item_description": ["Example item description"],
#>         "item_valueTemplate": ["string"],
#>         "item_validValues": [null],
#>         "item_validation": [null]
#>       }
#>     },
#>     "sections": {
#>       "example_section": {
#>         "section_id": ["example_section"],
#>         "section_label": ["Example Section"],
#>         "section_description": ["Example section description"]
#>       }
#>     },
#>     "valueTemplates": {
#>       "numeric": {
#>         "identifier": ["numeric"],
#>         "description": ["Any valid number"],
#>         "validValues": [null],
#>         "default": [null],
#>         "examples": ["2.3 || 643.2"],
#>         "validation": ["is.na(VALUE) || (is.numeric(VALUE) && (length(VALUE) == 1))"],
#>         "error": ["NAME is not numeric, or contains more than one value."]
#>       },
#>       "integer": {
#>         "identifier": ["integer"],
#>         "description": ["Any valid whole number"],
#>         "validValues": [null],
#>         "default": [null],
#>         "examples": ["30 || 8762"],
#>         "validation": ["is.na(VALUE) || (is.numeric(VALUE) && (VALUE%%1==0) && (length(VALUE) == 1))"],
#>         "error": ["NAME is not numeric, contains more than one value, or contains decimals."]
#>       },
#>       "string": {
#>         "identifier": ["string"],
#>         "description": ["A single character value"],
#>         "validValues": [null],
#>         "default": [null],
#>         "examples": ["&#39;Example&#39; || &#39;Another example&#39;"],
#>         "validation": ["is.na(VALUE) || (is.character(VALUE) && length(VALUE) == 1)"],
#>         "error": ["NAME is not a single text string."]
#>       },
#>       "categorical": {
#>         "identifier": ["categorical"],
#>         "description": ["A string that has to exactly match one of the values specified in the &#39;items_validValues&#39; column of the items sheet"],
#>         "validValues": [null],
#>         "default": [null],
#>         "examples": ["VALIDVALUES"],
#>         "validation": ["is.na(VALUE) || (VALUE %in% VALIDVALUES)"],
#>         "error": ["NAME is not one of VALIDVALUES."]
#>       }
#>     }
#>   }
#> }' class="preregr hidden" style="display:none"></div>