View source: R/write_dataset_description.R
| write_dataset_description | R Documentation |
Creates or updates dataset_description.json in the project root, which
the psych-DS standard requires. The
variables it describes are taken from the codebooks created by the codebook
chunk in code/processing.qmd, so that each variable is described once, in
the codebook, rather than twice.
write_dataset_description(
project_root,
name = NULL,
description = NULL,
quiet = FALSE
)
project_root |
Character scalar. Path to the project root, e.g.,
|
name |
Character scalar. The dataset's name. Defaults to the name in
an existing |
description |
Character scalar. A description of the dataset. Defaults to the description in an existing file, or a placeholder to complete by hand. |
quiet |
Logical. If |
Documenting variables in a codebook .csv is the simpler option, and is
all that validator() requires. Writing them to
dataset_description.json as well is more work, but makes the project
closer to a valid psych-DS dataset, which is machine-readable and easier
for others to reuse. Use whichever suits the project; you do not need both.
Each codebook row becomes a PropertyValue entry in variableMeasured,
mapping the codebook's variable, description, and units columns onto
name, description, and unitText. A coding entry that is not
"none" is appended to the description, because psych-DS has no separate
field for it. Where the same variable appears in more than one codebook,
the first description is used.
Fields that the file already contains and that this function does not
write (e.g., author or license) are kept.
Data file names in the templates follow the psych-DS convention of
key-value pairs ending in _data, e.g.,
study-1_stage-processed_data.csv. To check a project against the
standard itself, use the psych-DS validator
(https://psych-ds.github.io/validator/).
(Invisibly) a list with path, name, description, and variables
(the variable names written).
create_project_skeleton(), validator()
project <- file.path(tempdir(), "psychds_project")
create_project_skeleton(project, quiet = TRUE)
# normally written by the codebook chunk in code/processing.qmd
write.csv(
data.frame(
variable = c("id", "rt"),
description = c("Participant identifier", "Response time"),
units = c("none", "milliseconds"),
coding = c("none", "none")
),
file.path(project, "data", "processed", "stage-processed_codebook.csv"),
row.names = FALSE
)
write_dataset_description(project, name = "My study", description = "A demo")
cat(readLines(file.path(project, "dataset_description.json")), sep = "\n")
unlink(project, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.