Skip to content

descriptives: keep integer counts free of decimal places#452

Merged
jonathon-love merged 2 commits into
jamovi:mainfrom
raviselker:worktree-fix-decimal-counts-1797
Jun 13, 2026
Merged

descriptives: keep integer counts free of decimal places#452
jonathon-love merged 2 commits into
jamovi:mainfrom
raviselker:worktree-fix-decimal-counts-1797

Conversation

@raviselker

Copy link
Copy Markdown
Member

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

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.
Comment thread R/descriptives.b.R Outdated
# 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')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.
@jonathon-love jonathon-love merged commit cd0d3f3 into jamovi:main Jun 13, 2026
1 of 2 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.

counts displayed to decimal places

2 participants