write_dataset_description: Write a psych-DS dataset_description.json from the project's...

View source: R/write_dataset_description.R

write_dataset_descriptionR Documentation

Write a psych-DS dataset_description.json from the project's codebooks

Description

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.

Usage

write_dataset_description(
  project_root,
  name = NULL,
  description = NULL,
  quiet = FALSE
)

Arguments

project_root

Character scalar. Path to the project root, e.g., "../" from code/processing.qmd.

name

Character scalar. The dataset's name. Defaults to the name in an existing dataset_description.json, or the project folder's name.

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 FALSE (default), a one-line summary is printed as a message.

Details

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/).

Value

(Invisibly) a list with path, name, description, and variables (the variable names written).

See Also

create_project_skeleton(), validator()

Examples

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)


psychdsish documentation built on Nov. 29, 2026, 5:07 p.m.