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

713 summarize_occurrences_by_grade missing numeric grades bug #729

Merged
merged 4 commits into from
Oct 24, 2022
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* Replaced `synthetic_cdisc_data` with refactored `synthetic_cdisc_dataset` function to speed up dataset loading in tests/examples.
* Updated all tests to use `rcd_2022_06_27` version of cached data.

### Bug Fixes
* Fixed bug causing incorrect ordering of numeric grade levels when missing grades are present in `s_count_occurrences_by_grade`.

# tern 0.7.10

### New Features
Expand Down
9 changes: 8 additions & 1 deletion R/count_occurrences_by_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,14 @@ s_count_occurrences_by_grade <- function(df,

if (!is.ordered(grade)) {
grade_lbl <- obj_label(grade)
grade <- formatters::with_label(factor(grade, levels = levels(grade), ordered = TRUE), grade_lbl)
lvls <- levels(grade)
if (sum(grepl("^\\d+$", lvls)) %in% c(0, length(lvls))) {
lvl_ord <- lvls
} else {
lvls[!grepl("^\\d+$", lvls)] <- min(as.numeric(lvls[grepl("^\\d+$", lvls)])) - 1
lvl_ord <- levels(grade)[order(as.numeric(lvls))]
}
grade <- formatters::with_label(factor(grade, levels = lvl_ord, ordered = TRUE), grade_lbl)
}

df_max <- stats::aggregate(grade ~ id, FUN = max, drop = FALSE)
Expand Down