Skip to content

fix(metadata,cli): drop unnamed columns so R-exported CSVs validate (#109)#112

Closed
Mandyx22 wants to merge 1 commit into
mainfrom
fix/unnamed-leading-column
Closed

fix(metadata,cli): drop unnamed columns so R-exported CSVs validate (#109)#112
Mandyx22 wants to merge 1 commit into
mainfrom
fix/unnamed-leading-column

Conversation

@Mandyx22

Copy link
Copy Markdown
Contributor

What

Fixes finding #2 of #109: a real jsPsych dataset exported from R fails Psych-DS validation because of an unnamed row-index column.

R's write.csv (with the default row.names = TRUE) prepends an unnamed row-index column, so the CSV header starts with a bare comma — an empty-string column name. Psych-DS variables require a name, so the column can never appear in variableMeasured. Previously:

  • the library skipped it, logging Name field is missing. Variable not added. once per row, and
  • the CLI copied the CSV verbatim,

leaving a column in the file with no metadata entry and failing validation with CSV_COLUMN_MISSING_FROM_METADATA.

How

The library owns variableMeasured; the CLI owns the on-disk CSV — so both must agree, or the file the validator reads won't match the metadata.

  • stripUnnamedColumns(rows) — new exported helper in the metadata package that drops empty/whitespace-only-named columns in place and reports which were dropped.
  • generate() strips unnamed columns from the parsed data up front, with a single warning instead of per-row spam.
  • CLI writer re-serialises a .csv input that contains unnamed columns (column order preserved) so the written file matches variableMeasured; well-formed CSVs are still copied byte-for-byte. Mirrored on the JSON→CSV conversion path too.

Chose to drop the column (the issue's suggested option a) rather than synthesize a name — it's a meaningless row index, so dropping yields the least-surprising valid dataset.

Testing

🤖 Generated with Claude Code

…109)

R's write.csv(row.names=TRUE) prepends an unnamed row-index column, so the
header starts with a bare comma (an empty-string column name). Such a column
can't appear in variableMeasured (Psych-DS requires a name), so the library
skipped it while warning once per row, and the CLI copied the CSV verbatim —
leaving a column with no metadata and failing validation with
CSV_COLUMN_MISSING_FROM_METADATA.

generate() now strips empty/whitespace-only columns from parsed data up front
with a single warning, via a new exported stripUnnamedColumns helper. The CLI
re-serialises a .csv input that has unnamed columns (preserving column order)
so the written file matches variableMeasured; well-formed CSVs are still copied
byte-for-byte. Fixes finding #2 of #109.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 57b5bcf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@jspsych/metadata Patch
@jspsych/metadata-cli Patch
frontend Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Mandyx22

Copy link
Copy Markdown
Contributor Author

Superseded by #114 — finding #2 is re-cut on top of #103's shared buildPsychDSDataFiles so the CLI and frontend share one data-shaping path. The library stripUnnamedColumns + generate() strip here carry over; the CLI verbatim-write rewrite is replaced by the strip inside the shared builder. Closing to avoid review on the old shape.

@Mandyx22 Mandyx22 closed this Jun 16, 2026
jodeleeuw pushed a commit that referenced this pull request Jun 18, 2026
#109)

R's write.csv(row.names=TRUE) prepends an unnamed row-index column (empty-string
header). It can't appear in variableMeasured (Psych-DS requires a name), so
generate() drops it from the metadata — but the on-disk CSV kept it, failing
validation with CSV_COLUMN_MISSING_FROM_METADATA.

Put the strip in the shared data-file path so the CLI and frontend behave
identically (layered on #103's buildPsychDSDataFiles):

- New exported stripUnnamedColumns helper; generate() strips parsed data up front
  with a single warning (keeps variableMeasured clean + standalone use safe).
- buildPsychDSDataFiles strips the main table: a clean CSV keeps its exact bytes
  (verbatim mainContent), a dirty one is re-serialised from cleaned rows.
- CLI (rename-plan + non-plan paths) and frontend now feed parsed mainRows, so the
  written/zipped/validated CSV always matches the metadata.

Supersedes #112 and #113 (the CLI verbatim-write rewrite and the frontend-only
normalizeData helper) with one shared-builder implementation. Fixes finding #2 of #109.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jodeleeuw pushed a commit that referenced this pull request Jun 18, 2026
#109) (#114)

R's write.csv(row.names=TRUE) prepends an unnamed row-index column (empty-string
header). It can't appear in variableMeasured (Psych-DS requires a name), so
generate() drops it from the metadata — but the on-disk CSV kept it, failing
validation with CSV_COLUMN_MISSING_FROM_METADATA.

Put the strip in the shared data-file path so the CLI and frontend behave
identically (layered on #103's buildPsychDSDataFiles):

- New exported stripUnnamedColumns helper; generate() strips parsed data up front
  with a single warning (keeps variableMeasured clean + standalone use safe).
- buildPsychDSDataFiles strips the main table: a clean CSV keeps its exact bytes
  (verbatim mainContent), a dirty one is re-serialised from cleaned rows.
- CLI (rename-plan + non-plan paths) and frontend now feed parsed mainRows, so the
  written/zipped/validated CSV always matches the metadata.

Supersedes #112 and #113 (the CLI verbatim-write rewrite and the frontend-only
normalizeData helper) with one shared-builder implementation. Fixes finding #2 of #109.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant