Skip to content

readDatasetFromJaspFile keeps the level order of the file - #25

Merged
boutinb merged 2 commits into
jasp-stats:masterfrom
boutinb:keepJaspFileFactorLevels
Nov 16, 2026
Merged

boutinb merged 2 commits into
jasp-stats:masterfrom
boutinb:keepJaspFileFactorLevels

Conversation

@boutinb

@boutinb boutinb commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Problem

readDatasetFromJaspFile() turned nominal and ordinal columns into character vectors. When that data.frame is loaded again with loadDataSet(), the levels are then ordered alphabetically instead of in the order of the file (the order JASP shows).

That changes results whenever the level order matters. For example, in puppies.jasp and puppy_love.jasp of jaspAnova, Dose has the levels "No puppies", "15 mins", "30 mins". Alphabetically "No puppies" comes last, so the simple contrasts use another reference level and the custom weights -2, 1, 1 apply to the wrong levels. jaspTools' extractDatasetFromJASPFile() + runAnalysis() therefore gave other contrast tables than those saved in the file.

Change

readDatasetFromJaspFile() now keeps the factors the bridge gives (normalize = FALSE): nominal columns are factors, ordinal columns ordered factors, with their levels in file order. loadDataSet() keeps that order since #19.

  • Docs of readDatasetFromJaspFile updated.
  • New test test-jasp-file-factor-levels.R on fixtures/jasp-files/puppies-levels.jasp (puppies.jasp without its results, 12 KB): the level order is that of the file, and it survives loadDataSet().
  • The runner test now expects normalize = FALSE.

With this change, the old jaspTools path gives the contrast tables saved in both files.

Behaviour change for callers: categorical columns come back as factors instead of characters. jaspTools' tests of extractDatasetFromJASPFile() are updated for that in jasp-stats/jaspTools#101.

Version 1.4.3: this follows #24 (1.4.2). If this one is merged first, the version line conflicts trivially.

🤖 Generated with Claude Code

…columns

The bridge gives nominal columns as factors and ordinal columns as ordered
factors, with their levels in the order of the file, but
readDatasetFromJaspFile turned them into character vectors. Loaded again
with loadDataSet(), their levels were then ordered alphabetically: in
puppies.jasp (jaspAnova) Dose became "15 mins", "30 mins", "No puppies"
instead of "No puppies", "15 mins", "30 mins", so its simple and custom
contrasts compared other levels than in JASP. The factors are now kept, and
loadDataSet() keeps their level order (jasp-stats#19).

Version 1.4.3 (after 1.4.2 of readAnalysisResultsFromJaspFile).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
boutinb added a commit to jasp-stats/jaspTools that referenced this pull request Nov 16, 2026
jaspSyntax 1.4.3 (jasp-stats/jaspSyntax#25) gives nominal and ordinal columns as
factors with their levels in the order of the file, instead of character vectors.
The tests compare categorical columns by their values, so they pass with both.

Co-Authored-By: Claude Opus 5.5 <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