From 95f8e4b2f6a9e3173ce7d006881cdfdb963ca1ab Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Mon, 28 Aug 2023 10:50:20 -0400 Subject: [PATCH 1/4] Reorder grade levels without relabelling --- R/count_occurrences_by_grade.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/count_occurrences_by_grade.R b/R/count_occurrences_by_grade.R index 3ea79c806b..66aae21e6d 100644 --- a/R/count_occurrences_by_grade.R +++ b/R/count_occurrences_by_grade.R @@ -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)) From c160bfada34e9be3243f4f6a0d400a92b7dbbdbc Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Mon, 28 Aug 2023 10:57:10 -0400 Subject: [PATCH 2/4] Update NEWS, tests --- NEWS.md | 1 + tests/testthat/_snaps/count_occurrences_by_grade.md | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index d7ca8b59a5..e5266157b0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ ### 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 `s_count_occurrences_by_grade` so that levels are not relabelled when reordering to account for "missing" grades. ### Miscellaneous * Fix swapped descriptions for the `.N_row` and `.N_col` parameters. diff --git a/tests/testthat/_snaps/count_occurrences_by_grade.md b/tests/testthat/_snaps/count_occurrences_by_grade.md index ac93d474d5..646bc81f26 100644 --- a/tests/testthat/_snaps/count_occurrences_by_grade.md +++ b/tests/testthat/_snaps/count_occurrences_by_grade.md @@ -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 From ba85acc777b95d9dced47df634bf964023841d6e Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Mon, 28 Aug 2023 11:02:19 -0400 Subject: [PATCH 3/4] Fix Canadian spelling --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e5266157b0..69c8727baa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,7 +8,7 @@ ### 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 `s_count_occurrences_by_grade` so that levels are not relabelled when reordering to account for "missing" grades. +* 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. From 5c539393b1daccf659a8f1fc0d70a94778107b83 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Mon, 28 Aug 2023 11:27:00 -0400 Subject: [PATCH 4/4] Fix NEWS grammar --- NEWS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 69c8727baa..069e1ea3af 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,12 +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