fix: make factor level labels name-safe in Process models#211
Merged
Conversation
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>
Contributor
|
Do you mean, it fixes jasp-stats/jasp-issues#3597 instead ? |
Contributor
Author
|
build |
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). |
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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