Skip to content

setup_datadict(): generate a tidyverse data-dict.yaml from the dictionary and tidy data #105

Description

@larnsce

Motivation

tidyverse/data-dict is an emerging YAML specification (v0.1.0) for data dictionaries: semantic types (number(id), number(quantity) + units, enum + values), constraints (primary_key, foreign_key, required, assertions), cross-table relationships, and a domain glossary — all machine-readable and AI-agent-readable. Full analysis: dev/research-data-dict-integration.md.

data-raw/dictionary.csv is a flat, weaker version of one tables: block. This issue is the additive first step (Option A in the research doc): keep the CSV as the authoring surface and generate data-dict.yaml from it, the same way setup_roxygen() and generate_jsonld() are downstream renderings today.

Proposal

New exported function setup_datadict() (with an update_datadict() re-run path, consistent with the v1.1.0 idempotency sweep in #73) that writes data-dict.yaml at the package root:

  • dataset-level name / description from DESCRIPTION (via desc)
  • one tables: entry per .rda in data/
  • column name and description from data-raw/dictionary.csv
  • type mapped from R classes: character → string, numeric/integer → number, factor → enum + values from levels, logical → boolean, Date → date, POSIXct → datetime
  • examples: (first ~5 distinct values) and range: (min/max for numeric/date) drawn from the data — cheap since collect_tidydata_info() already loads every dataset

YAML emission via yaml::write_yaml() (one small new dependency). No dependency on the Rust CLI — generation is pure R.

Acceptance criteria

  • Running setup_datadict() on a package with a completed dictionary produces a data-dict.yaml that passes data-dict validate-spec
  • Re-running preserves hand-added enrichments (units, constraints) or clearly documents the regeneration contract
  • Behavioral test per the v1.2.0 test bar; documented in the vignette

Related: #13 (updating an existing dictionary), #83 (AI-assisted descriptions — data-dict ships agent skills for authoring dictionaries).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions