Title: | Specify (Pre)Registrations and Export Them Human- And Machine-Readably |
---|---|
Description: | Preregistrations, or more generally, registrations, enable explicit timestamped and (often but not necessarily publicly) frozen documentation of plans and expectations as well as decisions and justifications. In research, preregistrations are commonly used to clearly document plans and facilitate justifications of deviations from those plans, as well as decreasing the effects of publication bias by enabling identification of research that was conducted but not published. Like reporting guidelines, (pre)registration forms often have specific structures that facilitate systematic reporting of important items. The 'preregr' package facilitates specifying (pre)registrations in R and exporting them to a human-readable format (using R Markdown partials or exporting to an 'HTML' file) as well as human-readable embedded data (using 'JSON'), as well as importing such exported (pre)registration specifications from such embedded 'JSON'. |
Authors: | Gjalt-Jorn Peters [aut, cre] , Szilvia Zörgő [ctb] , Olmo den Akker [ctb] , Aleksandra Lazić [ctb] , Thomas Gültzow [ctb] |
Maintainer: | Gjalt-Jorn Peters <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.9 |
Built: | 2024-12-18 06:29:15 UTC |
Source: | CRAN |
"Bipiped" means that different values are separated by a pair of
pipes (||
), like the logical OR operator in R. Use
bipiped_value_to_vector()
for single values, and
bipiped_values_to_vector()
for a vector of values, in which case a list
is returned.
bipiped_value_to_vector(x) bipiped_values_to_vector(x)
bipiped_value_to_vector(x) bipiped_values_to_vector(x)
x |
The value or vector of values. |
A vector or list of vectors.
exampleValue <- paste0('"Purposefully select" || "Aselect" || ', '"Likely self-selected" || "Ameliorated self-selection"'); bipiped_value_to_vector(exampleValue);
exampleValue <- paste0('"Purposefully select" || "Aselect" || ', '"Likely self-selected" || "Ameliorated self-selection"'); bipiped_value_to_vector(exampleValue);
The cat0 function is to cat what paste0 is to paste; it simply makes concatenating many strings without a separator easier.
cat0(..., sep = "")
cat0(..., sep = "")
... |
The character vector(s) to print; passed to cat. |
sep |
The separator to pass to cat, of course, |
Nothing (invisible NULL
, like cat).
cat0("The first variable is '", names(mtcars)[1], "'.");
cat0("The first variable is '", names(mtcars)[1], "'.");
This is a simple and relatively short partially completed (pre)registration specification.
examplePrereg_1
examplePrereg_1
An example of a (pre)registration specification
From a vector or list of values, select the first valid value, valid being defined as a value that is not NULL or NA and has, after being trimmed of whitespace, a nonzero length. Optionally, only look at the element with a given name.
first_valid_value(x, selectName = NULL)
first_valid_value(x, selectName = NULL)
x |
The vector or list. |
selectName |
Optionally, the name to look at. |
The first valid value (or NULL).
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 )
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 )
x |
The (pre)registration form as created by |
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) |
The modified (pre)registration form
### Create an empty example form exampleForm <- preregr::form_create( title = "Example form", version = "0.1.0" ) |> preregr::form_show(); ### 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);
### Create an empty example form exampleForm <- preregr::form_create( title = "Example form", version = "0.1.0" ) |> preregr::form_show(); ### 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);
This form specification is mostly empty, so it can be a useful start if you want to create your own form. The accompanying Google Sheet, which you can also copy, is https://docs.google.com/spreadsheets/d/14Qbak7JbBhTqmJaMgJ4tU9ZROaBbUfq37_UzkoHnM60
form_almostEmptyForm
form_almostEmptyForm
A (pre)registration specification
You can use this function to create a new (pre)registration form.
The "Creating a (pre)registration form" vignette explains how this works.
That is available at
https://preregr.opens.science/articles/creating_prereg_form.html
or can be shown by running vignette("creating_prereg_form",
package = "preregr")
.
form_create( title, version, author = NA, date = format(Sys.Date(), "%Y-%m-%d"), ... )
form_create( title, version, author = NA, date = format(Sys.Date(), "%Y-%m-%d"), ... )
title |
The form's title |
version |
The form's version. If there is only one version and the
creators do not plan to release future version, the recommendation is to
set the version to |
author |
The authors of the form |
date |
The date the form was created |
... |
Additional field-content pairs to specify arbitrary metadata. |
The preregr
form object prefilled with some examples.
exampleForm <- preregr::form_create( title = "Example form", version = "0.1.0" ); ### Show the form summary exampleForm;
exampleForm <- preregr::form_create( title = "Example form", version = "0.1.0" ); ### Show the form summary exampleForm;
With this function, you can import a (pre) registration from a
spreadsheet. See the "Creating a form from a spreadsheet" vignette
for more information. That is available at
https://preregr.opens.science/articles/creating_form_from_spreadsheet.html
or can be shown by running vignette("creating_form_from_spreadsheet",
package = "preregr")
form_fromSpreadsheet( x, localBackup = NULL, exportGoogleSheet = TRUE, xlsxPkg = c("rw_xl", "openxlsx", "XLConnect"), silent = preregr::opts$get("silent") )
form_fromSpreadsheet( x, localBackup = NULL, exportGoogleSheet = TRUE, xlsxPkg = c("rw_xl", "openxlsx", "XLConnect"), silent = preregr::opts$get("silent") )
x |
The URL or path to a file. |
localBackup |
If not |
exportGoogleSheet |
If |
xlsxPkg |
Which package to use to work with Excel spreadsheets. |
silent |
Whether to be silent or chatty. |
An empty simple
example spreadsheet is available at
https://docs.google.com/spreadsheets/d/14Qbak7JbBhTqmJaMgJ4tU9ZROaBbUfq37_UzkoHnM60
and can be initialized as the almostEmptyForm
form
with prereg_initialize()
The preregr form specification
This Inclusive General-Purpose Registration Form is designed to be applicable across disciplines (i.e., psychology, economics, law, physics, or any other field) and across study types (i.e., qualitative studies, quantitative studies, experiments, systematic reviews, case studies, archive studies, comparative legal studies, or any other type of study). This form, therefore, is a fall-back for more specialized forms and can be used if no specialized form or registration platform is available. If at all possible, it is recommended to use a specialized form, since this inclusive general-purpose registration form achieves that inclusiveness and general-purposeness at the cost of specificity and comprehensiveness. Still, if specialized forms don't fit for your study, this form may be a good backup.
form_generalPurpose_v1_1
form_generalPurpose_v1_1
A (pre)registration form specification
This paper presents a generalized registration form for systematic reviews that can be used when currently available forms are not adequate. The form is designed to be applicable across disciplines (i.e., psychology, economics, law, physics, or any other field) and across review types (i.e., scoping review, review of qualitative studies, meta-analysis, or any other type of review). That means that the reviewed records may include research reports as well as archive documents, case law, books, poems, etc. Items were selected and formulated to optimize broad applicability instead of specificity, forgoing some benefits afforded by a tighter focus. This PRISMA 2020 compliant form is a fallback for more specialized forms and can be used if no specialized form or registration platform is available. When accessing this form on the Open Science Framework website, users will therefore first be guided to specialized forms when they exist. In addition to this use case, the form can also serve as a starting point for creating registration forms that cater to specific fields or review types.
form_genSysRev_v1
form_genSysRev_v1
A (pre)registration form specification
This form is meant as a generic add-on that can be added to any preregistration form to ensure that researchers are mindful about issues related to inclusivity and diversity. With inclusivity we mean "The fact or quality of being inclusive; (now) esp. the practice or policy of not excluding any person on the grounds of race, gender, religion, age, disability, etc.; inclusiveness." (Oxford University Press, n.d.-b).
form_inclDivAddon_v0_1
form_inclDivAddon_v0_1
A (pre)registration specification
With diversity we refer to "The fact, condition, or practice of including or involving people from a range of different social and ethnic backgrounds, and (more recently) of different genders, sexual orientations, etc." (Oxford University Press, n.d.-a).
Oxford University Press. (n.d.-a). Diversity, n. In OED Online. Oxford University Press. Retrieved November 29, 2022, from https://www.oed.com/view/Entry/56064
Oxford University Press. (n.d.-b). Inclusivity, n. In OED Online. Oxford University Press. Retrieved November 29, 2022, from https://www.oed.com/view/Entry/93584"
This Systematic Review Registration Form is intended as a general-purpose registration form. The form is designed to be applicable to reviews across disciplines (i.e., psychology, economics, law, physics, or any other field) and across review types (i.e., scoping review, review of qualitative studies, meta-analysis, or any other type of review). That means that the reviewed records may include research reports as well as archive documents, case law, books, poems, etc. This form, therefore, is a fall-back for more specialized forms and can be used if no specialized form or registration platform is available.
form_inclSysRev_v0_92
form_inclSysRev_v0_92
A (pre)registration form specification
This function inserts a (pre)registration form, or one or more sections, into an R Markdown file.
form_knit(x, section = NULL, headingLevel = 2)
form_knit(x, section = NULL, headingLevel = 2)
x |
The (pre)registration form (as produced by a call
to |
section |
The section(s) to show; pass |
headingLevel |
The level to use for the top-most heading. |
x, invisibly
preregr::form_create( title = "Example form", version = "0.1.0" ) |> preregr::form_knit();
preregr::form_create( title = "Example form", version = "0.1.0" ) |> preregr::form_knit();
Preregistration is the act of submitting a study plan, ideally also with analytical plan, to a registry prior to conducting the work. Preregistration increases the discoverability of research even if it does not get published further. Adding specific analysis plans can clarify the distinction between planned, confirmatory tests and unplanned, exploratory research.
form_OSFprereg_v1
form_OSFprereg_v1
A (pre)registration form specification
This preprint contains a template for the "OSF Prereg" form available from the OSF Registry. An earlier version was originally developed for the Preregistration Challenge, an education campaign designed to initiate preregistration as a habit prior to data collection in basic research, funded by the Laura and John Arnold Foundation (now Arnold Ventures) and conducted by the Center for Open Science. More information is available at https://www.cos.io/initiatives/prereg/, and other templates are available at: https://osf.io/zab38/"
The Qualitative Preregistration Template was created by researchers from the qualitative community for registration of primarily qualitative work. It is available as a registration option on the Open Science Framework (OSF).
form_OSFqual1_v1
form_OSFqual1_v1
A (pre)registration specification
This form was added to preregr
by Aleksandra Lazic.
Please cite the associated paper when using this preregistration template (see https://doi.org/10.15626/MP.2020.2625).
form_prereg2D_v1
form_prereg2D_v1
A (pre)registration specification
A preregistration is a way to design your research project before you begin and to document your decisions, rationale. A template such as this one can be employed to think about what you want to do and how, and subsequently, if you wish, you can submit the finished preregistration to a registry, such as OSF's (https://osf.io/registries/). This template was developed to aid the preregistration of quantitative ethnographic studies, but due to its modular nature, it can be employed for qualitative studies as well.
form_preregQE_v0_95
form_preregQE_v0_95
A (pre)registration form specification
doi:10.23668/psycharchives.4584
As an international effort toward increasing psychology’s commitment to creating a stronger culture and practice of preregistration, a multi-society Preregistration Task Force* was formed, following the 2018 meeting of the German Psychological Society in Frankfurt, Germany. The Task Force created a detailed preregistration template that benefited from the APA JARS Quantitative Research guidelines, as well as a comprehensive review of many other preregistration templates.
form_prpQuant_v1
form_prpQuant_v1
A (pre)registration form specification
doi:10.23668/psycharchives.4584
This function shows (parts of) a (pre)registration form.
form_show(x, section = NULL)
form_show(x, section = NULL)
x |
The (pre)registration form (as produced by a call to
|
section |
The section(s) to show; pass |
x, invisibly
### An empty form preregr::form_create( "Example form", version = "1" ) |> preregr::form_show(); ### A complete form preregr::prereg_initialize("inclSysRev_v0_92") |> preregr::form_show();
### An empty form preregr::form_create( "Example form", version = "1" ) |> preregr::form_show(); ### A complete form preregr::prereg_initialize("inclSysRev_v0_92") |> preregr::form_show();
Convert a (pre)registration form to html
form_to_html( x, file = NULL, section = NULL, headingLevel = 1, silent = preregr::opts$get("silent") )
form_to_html( x, file = NULL, section = NULL, headingLevel = 1, silent = preregr::opts$get("silent") )
x |
The (pre)registration form (as produced by a call
to |
file |
Optionally, a file to save the html to. |
section |
Optionally, one or multiple sections to include (if |
headingLevel |
The level of the top-most headings. |
silent |
Whether to be silent or chatty. |
x, invisibly
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Extract the form and show it as HTML preregr::form_to_html( examplePrereg_1 );
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Extract the form and show it as HTML preregr::form_to_html( examplePrereg_1 );
Convert a (pre)registration specification to YAML or JSON
form_to_json(x, file = NULL) prereg_spec_to_json(x, includeFormSpec = TRUE, file = NULL) ## S3 method for class 'preregr_json' print(x, ...) prereg_spec_to_yaml(x, includeFormSpec = TRUE, file = NULL) ## S3 method for class 'preregr_yaml' print(x, ...)
form_to_json(x, file = NULL) prereg_spec_to_json(x, includeFormSpec = TRUE, file = NULL) ## S3 method for class 'preregr_json' print(x, ...) prereg_spec_to_yaml(x, includeFormSpec = TRUE, file = NULL) ## S3 method for class 'preregr_yaml' print(x, ...)
x |
The (pre)registration object (as produced by a call to
|
file |
Optionally, a file to save the YAML or JSON to. |
includeFormSpec |
Whether to include the (pre)registration form specification. Note that this includes metadata about the form fields such as their labels and descriptions - without the form specification, only the item identifiers are stored. |
... |
Any additional arguments are ignored. |
If a file is specified to write, to, x
will be returned invisibly
to allow building a pipe chain; if file=NULL
, the resulting YAML/JSON
will be returned as a character vector.
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Export to YAML preregr::prereg_spec_to_json( examplePrereg_1 ); ### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Export to YAML preregr::prereg_spec_to_yaml( examplePrereg_1 );
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Export to YAML preregr::prereg_spec_to_json( examplePrereg_1 ); ### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Export to YAML preregr::prereg_spec_to_yaml( examplePrereg_1 );
This function creates an R Markdown template from a preregr (pre)registrations form specification. Pass it the URL to a Google Sheet holding the (pre)registration form specification (in preregr format), see the "Creating a form from a spreadsheet" vignette), the path to a file with a spreadsheet holding such a specification, or a loaded or imported preregr (pre)registration form.
form_to_rmd_template( x, file = NULL, title = NULL, author = NULL, date = "`r format(Sys.time(), '%Y-%m-%d at %H:%M:%S %Z (UTC%z)')`", output = "html_document", yaml = list(title = title, author = author, date = date, output = output), includeYAML = TRUE, chunkOpts = "echo=FALSE, results='hide'", justify = FALSE, headingLevel = 2, showSpecification = FALSE, preventOverwriting = preregr::opts$get("preventOverwriting"), silent = preregr::opts$get("silent") ) ## S3 method for class 'preregr_rmd_template' print(x, ...)
form_to_rmd_template( x, file = NULL, title = NULL, author = NULL, date = "`r format(Sys.time(), '%Y-%m-%d at %H:%M:%S %Z (UTC%z)')`", output = "html_document", yaml = list(title = title, author = author, date = date, output = output), includeYAML = TRUE, chunkOpts = "echo=FALSE, results='hide'", justify = FALSE, headingLevel = 2, showSpecification = FALSE, preventOverwriting = preregr::opts$get("preventOverwriting"), silent = preregr::opts$get("silent") ) ## S3 method for class 'preregr_rmd_template' print(x, ...)
x |
The (pre)registration form (as produced by a call
to |
file |
Optionally, a file to save the html to. |
title |
The title to specify in the template's YAML front matter. |
author |
The author to specify in the template's YAML front matter. |
date |
The date to specify in the template's YAML front matter. |
output |
The output format to specify in the template's YAML front matter. |
yaml |
It is also possible to specify the YAML front matter directly
using this argument. If used, it overrides anything specified in |
includeYAML |
Whether to include the YAML front matter or omit it. |
chunkOpts |
The chunk options to set for the chunks in the template. |
justify |
Whether to use |
headingLevel |
The level of the top-most heading to use (the title of the (pre)registration form). |
showSpecification |
Whether to show the specification in the Rmd
output. When |
preventOverwriting |
Set to |
silent |
Whether to be silent or chatty. |
... |
Additional argument are ignored. |
x, invisibly
preregr::form_create( title = "Example form", version = "0.1.0" ) |> preregr::form_to_rmd_template();
preregr::form_create( title = "Example form", version = "0.1.0" ) |> preregr::form_to_rmd_template();
Export a (pre)registration form to an Excel spreadsheet
form_to_xlsx(x, file)
form_to_xlsx(x, file)
x |
The (pre)registration form (as produced by a call
to |
file |
The file to write the spreadsheet to. |
x, invisibly
Show an overview of all included (pre)registration forms.
forms()
forms()
Invisibly, a list of form identifiers of the available forms.
forms();
forms();
This is just a convenience function to print a markdown or HTML heading at a given 'depth'.
heading( ..., headingLevel = preregr::opts$get("defaultHeadingLevel"), output = "markdown", cat = TRUE )
heading( ..., headingLevel = preregr::opts$get("defaultHeadingLevel"), output = "markdown", cat = TRUE )
... |
The heading text: pasted together with no separator. |
headingLevel |
The level of the heading; the default can be set
with e.g. |
output |
Whether to output to HTML (" |
cat |
Whether to cat (print) the heading or just invisibly return it. |
The heading, invisibly.
heading("Hello ", "World", headingLevel=5); ### This produces: "\n\n##### Hello World\n\n"
heading("Hello ", "World", headingLevel=5); ### This produces: "\n\n##### Hello World\n\n"
Import a (pre)registration specification from JSON embedded in HTML
import_from_html(x, select = 1)
import_from_html(x, select = 1)
x |
The HTML as URL, path to a file, or HTML that has already been imported to a character vector. |
select |
If multiple |
The (pre)registration specification.
### Note that this example writes to a local file! ### Temporary file to save to tmpFile <- tempfile(fileext = ".html"); ### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Save it to an HTML file preregr::prereg_spec_to_html( examplePrereg_1, file = tmpFile ); ### Import the example again importedPreregr <- preregr::import_from_html( tmpFile ); ### Show the result preregr::prereg_show_item_completion( importedPreregr, section="metadata" );
### Note that this example writes to a local file! ### Temporary file to save to tmpFile <- tempfile(fileext = ".html"); ### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Save it to an HTML file preregr::prereg_spec_to_html( examplePrereg_1, file = tmpFile ); ### Import the example again importedPreregr <- preregr::import_from_html( tmpFile ); ### Show the result preregr::prereg_show_item_completion( importedPreregr, section="metadata" );
Convert a number to a date using Excel's system
number_as_xl_date(x)
number_as_xl_date(x)
x |
The number(s) |
The date(s)
preregr::number_as_xl_date(44113);
preregr::number_as_xl_date(44113);
The preregr::opts
object contains three functions to set, get, and reset
options used by the preregr package. Use preregr::opts$set
to set options,
preregr::opts$get
to get options, or preregr::opts$reset
to reset specific or
all options to their default values.
opts
opts
An object of class list
of length 4.
It is normally not necessary to get or set preregr
options.
The following arguments can be passed:
For preregr::opts$set
, the dots can be used to specify the options
to set, in the format option = value
, for example, utteranceMarker = "\n"
. For
preregr::opts$reset
, a list of options to be reset can be passed.
For preregr::opts$set
, the name of the option to set.
For preregr::opts$get
, the default value to return if the
option has not been manually specified.
The following options can be set:
The prefix for quasi-unique record identifiers (QURIDs).
Second item
### Get the default "silence versus chattiness" setting preregr::opts$get(silent); ### Set it to show all messages preregr::opts$set(silent = FALSE); ### Check that it worked preregr::opts$get(silent); ### Reset this option to its default value preregr::opts$reset(silent); ### Check that the reset worked, too preregr::opts$get(silent);
### Get the default "silence versus chattiness" setting preregr::opts$get(silent); ### Set it to show all messages preregr::opts$set(silent = FALSE); ### Check that it worked preregr::opts$get(silent); ### Reset this option to its default value preregr::opts$reset(silent); ### Check that the reset worked, too preregr::opts$get(silent);
To initialize a (pre)registration, pass the URL to a Google Sheet holding the (pre)registration form specification (in preregr format), see the "Creating a form from a spreadsheet" vignette), the path to a file with a spreadsheet holding such a specification, or a loaded or imported preregr (pre)registration form.
prereg_initialize(x, initialText = "Unspecified")
prereg_initialize(x, initialText = "Unspecified")
x |
The (pre)registration form specification, as a URL to a Google Sheet or online file or as the path to a locally stored file. |
initialText |
The text to initialize every field with. |
For an introduction to working with preregr (pre)registrations, see the "Specifying preregistration content" vignette.
The empty (pre)registration specification.
preregr::prereg_initialize( "inclSysRev_v0_92" );
preregr::prereg_initialize( "inclSysRev_v0_92" );
Justify (and optionally specify) the content for one or more (pre)registration items
prereg_justify( x, item, decision = NULL, justification = NULL, assertion = NULL, source = NULL, content = NULL, append = TRUE, validate = TRUE, requireValidContent = TRUE, silent = preregr::opts$get("silent") )
prereg_justify( x, item, decision = NULL, justification = NULL, assertion = NULL, source = NULL, content = NULL, append = TRUE, validate = TRUE, requireValidContent = TRUE, silent = preregr::opts$get("silent") )
x |
The (pre)registration object (as produced by a call to
|
item |
The identifier of the item for which to specify the justification of the (pre)registration content. |
decision , justification , assertion , source
|
The decision(s) (with optionally nested within it, one or more justifications), justification(s) (with optionally nested within it, one or more assertions), assertion(s) (with optionally nested within it, one or more sources), or source(s). |
content |
Optionally, content to specify or append for this item. |
append |
Whether to replace ( |
validate |
Whether to validate the specified content for each item using the validation rules in the (pre)registration form. |
requireValidContent |
Whether to only store new content if it passes
validation. Note that this is ignored if |
silent |
Whether to be silent or chatty. |
x, invisibly
### Start with an empty form, then specify and justify ### content for an item. preregExampl <- preregr::prereg_initialize( "inclSysRev_v0_92" ) |> preregr::prereg_justify( item = "title", content = "Example title", decision = "We decide to call this study 'Example title'.", justification = "It seems a fitting title for an example." ) |> preregr::prereg_show_item_completion( section="metadata" );
### Start with an empty form, then specify and justify ### content for an item. preregExampl <- preregr::prereg_initialize( "inclSysRev_v0_92" ) |> preregr::prereg_justify( item = "title", content = "Example title", decision = "We decide to call this study 'Example title'.", justification = "It seems a fitting title for an example." ) |> preregr::prereg_show_item_completion( section="metadata" );
This function inserts the specified content for the items in a (pre)registration, or in one or more sections, into an R Markdown file.
prereg_knit_item_content(x, section = NULL, headingLevel = 2)
prereg_knit_item_content(x, section = NULL, headingLevel = 2)
x |
The (pre)registration object (as produced by a call to
|
section |
The section(s) to show; pass |
headingLevel |
The level to use for the top-most heading. |
x, invisibly
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Knit the contents of the "metadata" section ### as an R Markdown partial examplePrereg_1 |> preregr::prereg_knit_item_content( section="metadata" );
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Knit the contents of the "metadata" section ### as an R Markdown partial examplePrereg_1 |> preregr::prereg_knit_item_content( section="metadata" );
This function shows the next item (or items) in a (pre)registration for which to specify content (searching through all sections or through a selection of sections).
prereg_next_item(x, nrOfItems = 1, section = NULL)
prereg_next_item(x, nrOfItems = 1, section = NULL)
x |
The (pre)registration object (as produced by a call to
|
nrOfItems |
The number of items to complete to show. |
section |
The section(s) to search; pass |
x, invisibly
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Check next item examplePrereg_1 |> preregr::prereg_next_item(); ### Specify content for this item examplePrereg_1 <- preregr::prereg_specify( examplePrereg_1, funding = paste0( "No funding. There's never any ", "funding for this kind of stuff." ) ); ### Get the next three items preregr::prereg_next_item( examplePrereg_1, nrOfItems = 3 );
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Check next item examplePrereg_1 |> preregr::prereg_next_item(); ### Specify content for this item examplePrereg_1 <- preregr::prereg_specify( examplePrereg_1, funding = paste0( "No funding. There's never any ", "funding for this kind of stuff." ) ); ### Get the next three items preregr::prereg_next_item( examplePrereg_1, nrOfItems = 3 );
This function shows which items in a (pre)registration, or in one or more sections, have been completed - or, more accurately, contain at least some content that is different from the default content.
prereg_show_item_completion(x, section = NULL)
prereg_show_item_completion(x, section = NULL)
x |
The (pre)registration object (as produced by a call to
|
section |
The section(s) to show; pass |
x, invisibly
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Show which items were completed examplePrereg_1 |> preregr::prereg_show_item_completion( section="metadata" );
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Show which items were completed examplePrereg_1 |> preregr::prereg_show_item_completion( section="metadata" );
This function shows the specified content for the items in a (pre)registration, or in one or more sections.
prereg_show_item_content(x, section = NULL)
prereg_show_item_content(x, section = NULL)
x |
The (pre)registration object (as produced by a call to
|
section |
The section(s) to show; pass |
x, invisibly
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Show the item content for the "metadata" section examplePrereg_1 |> preregr::prereg_show_item_content( section="metadata" );
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Show the item content for the "metadata" section examplePrereg_1 |> preregr::prereg_show_item_content( section="metadata" );
Use this function to export your (pre)registration specification to an
HTML file. To instead embed it in an R Markdown file, use
prereg_knit_item_content()
.
prereg_spec_to_html( x, file = NULL, section = NULL, headingLevel = 1, silent = preregr::opts$get("silent") )
prereg_spec_to_html( x, file = NULL, section = NULL, headingLevel = 1, silent = preregr::opts$get("silent") )
x |
The (pre)registration object (as produced by a call to
|
file |
Optionally, a file to save the html to. |
section |
Optionally, one or multiple sections to include (if |
headingLevel |
The level of the top-most headings. |
silent |
Whether to be silent or chatty. |
The produced HTML, which will print in the viewer in RStudio.
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Convert it to HTML and show the result preregr::prereg_spec_to_html( examplePrereg_1 );
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Convert it to HTML and show the result preregr::prereg_spec_to_html( examplePrereg_1 );
Use this function to export your (pre)registration specification to a PDF
file. To embed it in an R Markdown file, use
prereg_knit_item_content()
instead.
prereg_spec_to_pdf( x, file, author = NULL, section = NULL, headingLevel = 1, silent = preregr::opts$get("silent") )
prereg_spec_to_pdf( x, file, author = NULL, section = NULL, headingLevel = 1, silent = preregr::opts$get("silent") )
x |
The (pre)registration object (as produced by a call to
|
file |
The filename to save the (pre)registration to. |
author |
The author to specify in the PDF. |
section |
Optionally, one or multiple sections to include (if |
headingLevel |
The level of the top-most headings. |
silent |
Whether to be silent or chatty. |
x, invisibly
### Use a temporary file to write to tmpFile <- tempfile(fileext = ".pdf"); ### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Only run this if you have a functional LaTeX installation if (FALSE) { preregr::prereg_spec_to_pdf( examplePrereg_1, file = tmpFile ); }
### Use a temporary file to write to tmpFile <- tempfile(fileext = ".pdf"); ### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Only run this if you have a functional LaTeX installation if (FALSE) { preregr::prereg_spec_to_pdf( examplePrereg_1, file = tmpFile ); }
Specify the content for one or more (pre)registration items
prereg_specify( x, ..., append = TRUE, validate = TRUE, requireValidContent = TRUE, silent = preregr::opts$get("silent") )
prereg_specify( x, ..., append = TRUE, validate = TRUE, requireValidContent = TRUE, silent = preregr::opts$get("silent") )
x |
The (pre)registration object (as produced by a call to
|
... |
Item-content pairings. |
append |
Whether to replace ( |
validate |
Whether to validate the specified content for each item using the validation rules in the (pre)registration form. |
requireValidContent |
Whether to only store new content if it passes
validation. Note that this is ignored if |
silent |
Whether to be silent or chatty. |
x, invisibly
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Specify some fields and show the results examplePrereg_1 |> preregr::prereg_specify( tasks_and_roles = "All authors contributed equally", nonExistent_item = "This can't be stored anywhere", start_date = "2021-9-01" ) |> preregr::prereg_show_item_completion( section="metadata" );
### Load an example (pre)registration specification data("examplePrereg_1", package = "preregr"); ### Specify some fields and show the results examplePrereg_1 |> preregr::prereg_specify( tasks_and_roles = "All authors contributed equally", nonExistent_item = "This can't be stored anywhere", start_date = "2021-9-01" ) |> preregr::prereg_show_item_completion( section="metadata" );
idSlug is a convenience function with swapped argument order.
randomSlug(x = 10, id = NULL, chars = c(letters, LETTERS, 0:9)) idSlug(id = NULL, x = 10, chars = c(letters, LETTERS, 0:9))
randomSlug(x = 10, id = NULL, chars = c(letters, LETTERS, 0:9)) idSlug(id = NULL, x = 10, chars = c(letters, LETTERS, 0:9))
x |
Length of slug |
id |
If not NULL, prepended to slug (separated with a dash) as id; in that case, it's also braces and a hash is added. |
chars |
Characters to sample from |
A character value.
randomSlug(); idSlug("identifier");
randomSlug(); idSlug("identifier");
Bind lots of dataframes together rowwise
rbind_df_list(x)
rbind_df_list(x)
x |
A list of dataframes |
A dataframe
rbind_df_list(list(Orange, mtcars, ChickWeight));
rbind_df_list(list(Orange, mtcars, ChickWeight));
Simple alternative for rbind.fill or bind_rows
rbind_dfs(x, y, clearRowNames = TRUE)
rbind_dfs(x, y, clearRowNames = TRUE)
x |
One dataframe |
y |
Another dataframe |
clearRowNames |
Whether to clear row names (to avoid duplication) |
The merged dataframe
rbind_dfs(Orange, mtcars);
rbind_dfs(Orange, mtcars);
Currently reads spreadsheets from Google Sheets or from xlsx
, csv
,
or sav
files. Normally, you don't use this, but instead you
use form_fromSpreadsheet()
.
read_spreadsheet( x, sheet = NULL, columnDictionary = NULL, localBackup = NULL, exportGoogleSheet = FALSE, flattenSingleDf = FALSE, xlsxPkg = c("rw_xl", "openxlsx", "XLConnect"), failQuietly = FALSE, silent = preregr::opts$get("silent") )
read_spreadsheet( x, sheet = NULL, columnDictionary = NULL, localBackup = NULL, exportGoogleSheet = FALSE, flattenSingleDf = FALSE, xlsxPkg = c("rw_xl", "openxlsx", "XLConnect"), failQuietly = FALSE, silent = preregr::opts$get("silent") )
x |
The URL or path to a file. |
sheet |
Optionally, the name(s) of the worksheet(s) to select. |
columnDictionary |
Optionally, a dictionary with column names to check for presence. A named list of vectors. |
localBackup |
If not |
exportGoogleSheet |
If |
flattenSingleDf |
Whether to return the result as a data frame if only one data frame is returned as a result. |
xlsxPkg |
Which package to use to work with Excel spreadsheets. |
failQuietly |
Whether to give an error when |
silent |
Whether to be silent or chatty. |
A list of dataframes, or, if only one data frame was loaded and
flattenSingleDf
is TRUE
, a data frame.
### Note that this example requires an internet connection! read_spreadsheet( paste0( "https://docs.google.com/", "spreadsheets/d/", "1bHDzpCu4CwEa5_3_q_9vH2691XPhCS3e4Aj_HLhw_U8" ) );
### Note that this example requires an internet connection! read_spreadsheet( paste0( "https://docs.google.com/", "spreadsheets/d/", "1bHDzpCu4CwEa5_3_q_9vH2691XPhCS3e4Aj_HLhw_U8" ) );
Repeat a string a number of times
repeatStr(n = 1, str = " ")
repeatStr(n = 1, str = " ")
n , str
|
Normally, respectively the frequency with which to repeat the string and the string to repeat; but the order of the inputs can be switched as well. |
A character vector of length 1.
### 10 spaces: repStr(10); ### Three euro symbols: repStr("\u20ac", 3);
### 10 spaces: repStr(10); ### Three euro symbols: repStr("\u20ac", 3);
When exporting a (pre)registration specification to YAML or JSON, the most human-readable format differs from the way data frames are comprised of lists. Data frames are lists that are bound together as columns; and so, when saving a data frame to YAML or JSON, the data in each column is combined (e.g. first all item identifiers, then all item labels, then all item descriptions, etc). However, for humans, it makes more sense to have all data belonging to the same item close together. These functions do that processing.
serialize_df(x, idCol = NULL) structure_for_serialization(x)
serialize_df(x, idCol = NULL) structure_for_serialization(x)
x |
For |
idCol |
If not |
The restructured list
In an object imported from YAML or JSON, convert some elements to dataframes
serialized_data_to_dfs(x)
serialized_data_to_dfs(x)
x |
The just imported (pre)registration specification |
The restructured object
These functions can be used to programmatically construct decision,
justifications, assertions, and sources using the justifier
package.
source(label, description = NULL, type = NULL, id = NULL, xdoi = NULL, ...) assert(label, description = "", type = NULL, id = NULL, source = NULL, ...) justify(label, description = "", type = NULL, id = NULL, assertion = NULL, ...) decide( label, description = NULL, type = NULL, id = NULL, alternatives = NULL, justification = NULL, ... )
source(label, description = NULL, type = NULL, id = NULL, xdoi = NULL, ...) assert(label, description = "", type = NULL, id = NULL, source = NULL, ...) justify(label, description = "", type = NULL, id = NULL, assertion = NULL, ...) decide( label, description = NULL, type = NULL, id = NULL, alternatives = NULL, justification = NULL, ... )
label |
A human-readable label for the |
description |
A human-readable description. This can be used to elaborate on the label. Note that the label should be reader-friendly and self-contained; but because they also have to be as short as possible, descriptions can be used to provide definitions, context, background information, or add any other metadata or comments. |
type |
Types are used when working with a framework. Frameworks define type identifiers, consisting of letters, digits, and underscores. By specifying these identifiers the type of a decision, justification, assertion, or source. Source types can be, for example, types of documents or other data providers, such as "empirical evidence', 'expert consensus', 'personal opinion', or 'that one meeting that we had in May'. Assertion types can be, for example, data types or types of facts, such as 'number', 'prevalence', 'causal relationship', or 'contact information'. Justification types can be, for example, types of reasoning or logical expressions, such as 'deduction', 'induction', or 'intersection'. Decision types are the most framework-specific, heavily depend on the specific context of the decision, and are used by frameworks to organise the decisions in a project. Examples of decision types are the decision to recruit a certain number of participants in a scientific study; the decision to target a certain belief in a behavior change intervention; the decision to merge two codes in a qualitative study; the decision to hire a staff member; or the decision to make a certain purchase. |
id |
The identifier (randomly generated if omitted). |
xdoi |
For |
... |
Additional fields and values to store in the element. |
source |
In assertions, the source (or sources) that the assertion
is based on can be specified using |
assertion |
In justifications, the assertion (or assertions) that
the justification is based on can be specified using |
alternatives |
The alternatives that were considered in a decision. |
justification |
In decisions, the justification (or justifications)
that the decision is based on can be specified using |
The generated object.
### Programmatically create a partial justification object exampleAssertion <- preregr::assert( "This is an assertion", source = c( preregr::source('This is a first source'), preregr::source('This is a second source'))); ### Programmatically create a justification with two assertions ### but without sources exampleJustification <- preregr::justify( "Icecream will make me feel less fit", assertion = c( preregr::assert('Icecream is rich in energy'), preregr::assert('Consuming high-energy foods makes me feel less fit') ), weight = -.5 ); ### Show it exampleJustification; ### Programmatically create a simple decision simpleDecision <- preregr::decide( "decision", justification = preregr::jstf( "justification", assertion = exampleAssertion ) ); ### Programmatically create a justification object for a full decision fullJustifierObject <- preregr::decide( "I decide to go get an icecream", justification = c( preregr::justify( "Having an icecream now would make me happy", assertion = c( preregr::assert( "Decreasing hunger increases happiness", source = preregr::source( "My past experiences" ) ), preregr::assert( "I feel hungry", source = preregr::source( "Bodily sensations" ) ) ), weight = 1 ), exampleJustification, preregr::justify( "I can afford to buy an icecream.", assertion = c( preregr::assert( "My bank account balance is over 300 euro.", source = preregr::source( "My bank app" ) ), preregr::assert( "I need to keep at least 100 euro in my bank account.", source = preregr::source( "Parental advice" ) ) ), weight = .3 ) ) ); ### Show the full object fullJustifierObject; ### Combine both into a list of decisions twoDecisions <- c(simpleDecision, fullJustifierObject); ### Show the combination twoDecisions;
### Programmatically create a partial justification object exampleAssertion <- preregr::assert( "This is an assertion", source = c( preregr::source('This is a first source'), preregr::source('This is a second source'))); ### Programmatically create a justification with two assertions ### but without sources exampleJustification <- preregr::justify( "Icecream will make me feel less fit", assertion = c( preregr::assert('Icecream is rich in energy'), preregr::assert('Consuming high-energy foods makes me feel less fit') ), weight = -.5 ); ### Show it exampleJustification; ### Programmatically create a simple decision simpleDecision <- preregr::decide( "decision", justification = preregr::jstf( "justification", assertion = exampleAssertion ) ); ### Programmatically create a justification object for a full decision fullJustifierObject <- preregr::decide( "I decide to go get an icecream", justification = c( preregr::justify( "Having an icecream now would make me happy", assertion = c( preregr::assert( "Decreasing hunger increases happiness", source = preregr::source( "My past experiences" ) ), preregr::assert( "I feel hungry", source = preregr::source( "Bodily sensations" ) ) ), weight = 1 ), exampleJustification, preregr::justify( "I can afford to buy an icecream.", assertion = c( preregr::assert( "My bank account balance is over 300 euro.", source = preregr::source( "My bank app" ) ), preregr::assert( "I need to keep at least 100 euro in my bank account.", source = preregr::source( "Parental advice" ) ) ), weight = .3 ) ) ); ### Show the full object fullJustifierObject; ### Combine both into a list of decisions twoDecisions <- c(simpleDecision, fullJustifierObject); ### Show the combination twoDecisions;
This function validates a value. Before validation, it checks
the validation expression and optionally performs replacements, where the
replacement strings (delimited by the validation replacement delimiters,
by default, {{
and }}
) are
replaced by the first valid corresponding value from the
replacementSources
(working through those sources consecutively, i.e.
only looking in the second one of the first one doesn't contain a valid
value for the relevant replacement string, valid being defined as a value
that is not NULL or NA and has, after being trimmed of whitespace, a
nonzero length).
validate_value( VALUE, validations, replacementSources, errorMessages, convert_bipiped = TRUE )
validate_value( VALUE, validations, replacementSources, errorMessages, convert_bipiped = TRUE )
VALUE |
The value to validate. |
validations |
The validations, a vector or list that will be consecutively searched for the first valid value (valid being defined as a value that is not NULL or NA and has, after being trimmed of whitespace, a nonzero length). That value has to be either as an R expression, or a character value (i.e. a length 1 character vector) that is a valid R expression, optionally after having performed the specified replacements. |
replacementSources |
A list of named lists (or 1-row data frames) that will be searched, consecutively, for values to replace the replacement strings with. |
errorMessages |
The errormessage to return if validation fails, of which the first valid one will be returned (valid being defined as a value that is not NULL or NA and has, after being trimmed of whitespace, a nonzero length). |
convert_bipiped |
Whether to first run |
To change the validation replacement delimiters, use
preregr::opts$set(validation_replacementDelimiters = c("{{", "}}"));
.
The message resulting from the validation (i.e. an error or "").
### Set some validation variables validationStatement <- paste( "is.na(VALUE) ||", "(VALUE %in% {{validValues}}) ||", "(VALUE %in% {{testField}})" ); replacementSources <- list( list(validValues = '"testValue" || "anotherValue"'), list(testField = "Yet another testvalue") ); errorMessages <- "No valid test value passed!"; ### Run a passing validation preregr::validate_value( "testValue", validations = validationStatement, replacementSources = replacementSources, errorMessages = errorMessages ); ### Run a failing validation preregr::validate_value( "A testvalue that won't pass", validations = validationStatement, replacementSources = replacementSources, errorMessages = errorMessages );
### Set some validation variables validationStatement <- paste( "is.na(VALUE) ||", "(VALUE %in% {{validValues}}) ||", "(VALUE %in% {{testField}})" ); replacementSources <- list( list(validValues = '"testValue" || "anotherValue"'), list(testField = "Yet another testvalue") ); errorMessages <- "No valid test value passed!"; ### Run a passing validation preregr::validate_value( "testValue", validations = validationStatement, replacementSources = replacementSources, errorMessages = errorMessages ); ### Run a failing validation preregr::validate_value( "A testvalue that won't pass", validations = validationStatement, replacementSources = replacementSources, errorMessages = errorMessages );
Easily parse a vector into a character value
vecTxt( vector, delimiter = ", ", useQuote = "", firstDelimiter = NULL, lastDelimiter = " & ", firstElements = 0, lastElements = 1, lastHasPrecedence = TRUE, colFun = NULL ) vecTxtQ(vector, useQuote = "'", ...)
vecTxt( vector, delimiter = ", ", useQuote = "", firstDelimiter = NULL, lastDelimiter = " & ", firstElements = 0, lastElements = 1, lastHasPrecedence = TRUE, colFun = NULL ) vecTxtQ(vector, useQuote = "'", ...)
vector |
The vector to process. |
delimiter , firstDelimiter , lastDelimiter
|
The delimiters
to use for respectively the middle, first
|
useQuote |
This character string is pre- and appended to all elements;
so use this to quote all elements ( |
firstElements , lastElements
|
The number of elements for which to use the first respective last delimiters |
lastHasPrecedence |
If the vector is very short, it's possible that the
sum of firstElements and lastElements is larger than the vector length. In
that case, downwardly adjust the number of elements to separate with the
first delimiter ( |
colFun |
A function to use for coloring. |
... |
Any addition arguments to |
A character vector of length 1.
vecTxtQ(names(mtcars));
vecTxtQ(names(mtcars));
Wrap all elements in a vector
wrapVector(x, width = 0.9 * getOption("width"), sep = "\n", ...)
wrapVector(x, width = 0.9 * getOption("width"), sep = "\n", ...)
x |
The character vector |
width |
The number of |
sep |
The glue with which to combine the new lines |
... |
Other arguments are passed to |
A character vector
res <- wrapVector( c( "This is a sentence ready for wrapping", "So is this one, although it's a bit longer" ), width = 10 ); print(res); cat(res, sep="\n");
res <- wrapVector( c( "This is a sentence ready for wrapping", "So is this one, although it's a bit longer" ), width = 10 ); print(res); cat(res, sep="\n");
Convert a (pre)registration specification from YAML or JSON
yaml_to_prereg_spec(x)
yaml_to_prereg_spec(x)
x |
The YAML or JSON as character vector, or a path to a file containing the YAML or JSON. |
The imported object.
### Get path to example file examplePreregFile <- system.file( "extdata", "preregr-spec-example1.yml", package = "preregr" ); ### Load it and show which items are completed preregr::yaml_to_prereg_spec( examplePreregFile ) |> preregr::prereg_show_item_completion();
### Get path to example file examplePreregFile <- system.file( "extdata", "preregr-spec-example1.yml", package = "preregr" ); ### Load it and show which items are completed preregr::yaml_to_prereg_spec( examplePreregFile ) |> preregr::prereg_show_item_completion();