Repository navigation
fixef(): keep digit-only labels as text when sorting - #705
Merged
Merged
Conversation
With sorted = TRUE, fixef() replaced fixed-effect labels made only of digits by as.numeric(labels) to sort them, so "00001" came back as "1". The names then no longer matched the data, and anything that maps data to fixef() names failed silently: sparse_model_matrix(type = "fixef") left every unit column empty (sum 100 instead of 190 in the lrberge#674 example). Sort such labels as numbers but keep their original text. The order is unchanged; fixed effects stored as numbers were already "1", "2", ... and are unaffected. Closes lrberge#674. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
@lrberge the code looks good to me; maybe no need for the test? |
This was referenced Nov 15, 2026
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.
Closes #674.
With
sorted = TRUE(the default),fixef()sorts labels made only of digits by replacing them withas.numeric(labels), so"00001"comes back as"1":https://github.com/lrberge/fixest/blob/cf946133/R/methods.R#L1366
The names then no longer match the data, and code that maps data to
fixef()names fails silently. In the #674 example,sparse_model_matrix(type = "fixef")leaves every unit column empty:The labels are still ordered as numbers, so the order is unchanged. They now keep their original text. Fixed effects stored as numbers already had names "1", "2", ... and are unaffected.
Tests, added to the
FIXEFchunk:sparse_model_matrixhas one 1 per row;The first test fails on master.
tests/fixest_tests.Rruns to completion on this branch and merged with #703 and #704.🤖 Generated with Claude Code