descriptives: keep integer counts free of decimal places#452
Merged
jonathon-love merged 2 commits intoJun 13, 2026
Conversation
Frequency counts were typed as 'number' when weights support was added, so even unweighted or integer-weighted counts displayed decimal places. Default the column to integer and switch to number only when the counts are actually non-integer. The case values are unavailable during init, so the type is determined in the run phase.
| # counts type here; only show decimals for non-integer counts | ||
| # (i.e. when weighted by non-integer weights) | ||
| if ( ! all(freq == round(freq), na.rm=TRUE)) | ||
| table$addColumn(name='counts', title=.('Counts'), type='number') |
Member
There was a problem hiding this comment.
this is relying on some undocumented feature, where if you add a column with the same name as an existing column, it replaces it?
this would be a different way to do it:
table$columns[['counts']]$.__enclos_env__$private$.type <- 'number'
Member
Author
There was a problem hiding this comment.
Went with the private$.type approach. One caveat: it can't be a single chained assignment —
table$columns[['counts']]$.__enclos_env__$private$.type <- 'number'
R desugars that into get-then-set-back calls up to the top-level target, so the final step writes the column list back through table$columns, which is a read-only active binding. That throws unused argument (... list(<environment> x4)). Extracting the column into a local first avoids the writeback:
countsColumn <- table$columns[['counts']]
countsColumn$.__enclos_env__$private$.type <- 'number'
Re-adding the 'counts' column via addColumn relied on implicit column replacement. Mutate the existing column's type instead. Extract the column to a local first; a chained assignment writes back through the read-only columns active binding and errors.
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.
Frequency counts were typed as 'number' when weights support was added, so even unweighted or integer-weighted counts displayed decimal places. Default the column to integer and switch to number only when the counts are actually non-integer. The case values are unavailable during init, so the type is determined in the run phase.
Closes jamovi/jamovi#1797