Skip to content

fix: make factor level labels name-safe in Process models#211

Merged
JohnnyDoorn merged 1 commit into
jasp-stats:masterfrom
JohnnyDoorn:fix-spaces
Jun 25, 2026
Merged

fix: make factor level labels name-safe in Process models#211
JohnnyDoorn merged 1 commit into
jasp-stats:masterfrom
JohnnyDoorn:fix-spaces

Conversation

@JohnnyDoorn

@JohnnyDoorn JohnnyDoorn commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Factor dummy variables are named and those names are later parsed as code: as R expressions in mean-centering (str2lang) and as lavaan model syntax. A level label containing a space or other character that is invalid inside a name (e.g. "emotion regulation", "self-help") therefore crashed the analysis. .procSafeFactorLevels() now coerces level labels to valid names before they are used; the level is always prefixed by the factor name, so leading digits and purely numeric levels are left unchanged.

Fix jasp-stats/jasp-issues#3597

Factor dummy variables are named <factor><level> and those names are later
parsed as code: as R expressions in mean-centering (str2lang) and as lavaan
model syntax. A level label containing a space or other character that is
invalid inside a name (e.g. "emotion regulation", "self-help") therefore
crashed the analysis. .procSafeFactorLevels() now coerces level labels to
valid names before they are used; the level is always prefixed by the factor
name, so leading digits and purely numeric levels are left unchanged.

Adds unit tests for the new helper and a NEWS entry.

Fixes jasp-stats/jasp-issues#3597

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@boutinb

boutinb commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Fix jasp-stats/jasp-issues#359

Do you mean, it fixes jasp-stats/jasp-issues#3597 instead ?

@JohnnyDoorn

Copy link
Copy Markdown
Contributor Author

build

@github-actions

Copy link
Copy Markdown
Contributor

✅ Build Complete!

Your JASP module bundles have been successfully built for macOS (ARM) and Windows.

👉 Click here to download the artifacts

(Scroll to the bottom of the page to find the "Artifacts" section).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes crashes in Process models caused by factor level labels that contain spaces or other special characters, which previously produced invalid dummy-variable names that were later parsed as R expressions (mean-centering) and lavaan syntax.

Changes:

  • Introduces .procSafeFactorLevels() to coerce declared factor level labels to name-safe equivalents and ensure uniqueness.
  • Applies this sanitization before factor dummy/interaction variables are generated in .procAddFactorDummyIntVars().
  • Adds unit tests covering special characters, numeric/valid levels, collisions, and non-factor columns; documents the fix in NEWS.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
R/classicProcess.R Adds .procSafeFactorLevels() and calls it before constructing dummy/interaction variables to prevent later parsing errors.
tests/testthat/test-classic-process-unit.R Adds unit tests verifying sanitization behavior, collision handling, and scope (only declared factors).
NEWS.md Documents the fix under the development-version changelog.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JohnnyDoorn JohnnyDoorn merged commit bd4c9c2 into jasp-stats:master Jun 25, 2026
4 of 7 checks passed
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.

[Bug]: error when second level in categorical predictor has a space

3 participants