Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder grade levels without relabelling in s_count_occurrences_by_grade #1044

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

### Bug Fixes
* Fixed bug in `s_count_occurrences_by_grade` so that "missing" grade always appears as the final level.
* Fix bug in `analyze_vars_in_cols` when categorical data was used.
* Fixed bug in `analyze_vars_in_cols` when categorical data was used.
* Fixed bug in `s_count_occurrences_by_grade` so that levels are not relabeled when reordering to account for "missing" grades.

### Miscellaneous
* Fix swapped descriptions for the `.N_row` and `.N_col` parameters.
* Removal of internal calls to `df_explicit_na`. Changes in `NA` values should happen externally to `tern` functions, depending on users' needs.
* Fixed swapped descriptions for the `.N_row` and `.N_col` parameters.
* Removed internal calls to `df_explicit_na`. Changes in `NA` values should happen externally to `tern` functions, depending on users' needs.
* Reinstated correct soft deprecation for `create_afun_summary` and `create_afun_compare`.

# tern 0.8.5
Expand Down
6 changes: 5 additions & 1 deletion R/count_occurrences_by_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ s_count_occurrences_by_grade <- function(df,

missing_lvl <- grepl("missing", tolower(levels(grade)))
if (any(missing_lvl)) {
levels(grade) <- c(levels(grade)[!missing_lvl], levels(grade)[missing_lvl])
grade <- factor(
grade,
levels = c(levels(grade)[!missing_lvl], levels(grade)[missing_lvl]),
ordered = is.ordered(grade)
)
}
df_max <- stats::aggregate(grade ~ id, FUN = max, drop = FALSE)
l_count <- as.list(table(df_max$grade))
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/count_occurrences_by_grade.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,22 @@
Output
$count_fraction
$count_fraction$`1`
[1] 0 0
[1] 2.0 0.2

$count_fraction$`2`
[1] 2.0 0.2

$count_fraction$`3`
[1] 2.0 0.2
[1] 1.0 0.1

$count_fraction$`4`
[1] 2.0 0.2
[1] 0 0

$count_fraction$`5`
[1] 0 0

$count_fraction$Missing
[1] 0 0
[1] 1.0 0.1



Expand Down