Skip to content
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
27 changes: 27 additions & 0 deletions R/updateColumnValues.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#' Update values in a summarised result
#'
#' @description
#' Updates the character values of specific column(s) in a summarised result object
#' (e.g., changing cohort names to a more polished version for Shiny app labels)
#' according to a given name mapping.
#'
#' @param summarised_result The summarised result with values to update.
#' @param names_map A named vector containing the mapping between old and new names.
#' @param variable The column name(s) containing the values to be updated in the
#' summarised result object.
#'
#' @returns The summarised result itself with updated values.
#'
updateColumnValues <- function(
summarised_result,
names_map,
variable
) {

summarised_result[[variable]] <- dplyr::recode(
summarised_result[[variable]],
!!!names_map
)

return(summarised_result)
}
24 changes: 24 additions & 0 deletions man/updateColumnValues.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions tests/testthat/test-cdmNames.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("assertCdmNames works", {
# Assert a group of acryonims
# Assert a group of acronyms
labels <- c(
"BCR",
"IQVIA LPD Belgium",
Expand All @@ -9,9 +9,9 @@ test_that("assertCdmNames works", {
)
assertCdmNames(labels = labels) |>
expect_invisible()
# Error acronim do not match
# Error acronym do not match
labels <- c(
"BCRX", # Mispelled acronym
"BCRX", # Misspelled acronym
"IQVIA LPD Belgium",
"NLHR@UiO:PERINATAL",
"IQVIA US - AmbEMR",
Expand All @@ -22,7 +22,7 @@ test_that("assertCdmNames works", {
})

test_that("assertCdmNames against expected acronyms", {
# Assert a group of acryonims
# Assert a group of acronyms
labels <- c(
"BCR",
"IQVIA LPD Belgium",
Expand All @@ -42,7 +42,7 @@ test_that("assertCdmNames against expected acronyms", {
expect_error()
# Incorrect acronym
labels <- c(
"BCRX", # Mispelled acronym
"BCRX", # Misspelled acronym
"IQVIA LPD Belgium",
"NLHR@UiO:PERINATAL",
"IQVIA US - AmbEMR",
Expand Down Expand Up @@ -78,9 +78,9 @@ test_that("arrangeCdmNames returns required acronyms in order", {
"IQVIA US - AmbEMR",
"IQVIA US - PMTX+"
))
# Error acronim do not match
# Error acronym do not match
labels <- c(
"BCRX", # Mispelled acronym
"BCRX", # Misspelled acronym
"IQVIA LPD Belgium",
"NLHR@UiO:PERINATAL",
"IQVIA US - AmbEMR",
Expand Down
48 changes: 48 additions & 0 deletions tests/testthat/test-updateColumnValues.R

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.

nice function for the test summarised result. Maybe omopgenerics has some test function for that?

@laacri laacri Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I used the example from omopgenerics::newSummarisedResult()'s documentation. I think there is no specific function to generate mock data in omopgenerics, but there is instead a mockSummarisedResult() function from the visOmopResults package and some other functionalities from omock

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
test_that("updateColumnValues updates summarised result correctly", {

# Create mock summarised result
x <- dplyr::tibble(
"result_id" = 1L,
"cdm_name" = "cprd",
"group_name" = "cohort_name",
"group_level" = c(
"acetaminophen",
"acetaminophen",
"diclofenac",
"ibuprofen"
),
"strata_name" = "sex &&& age_group",
"strata_level" = c(
"male &&& <40",
"male &&& >=40",
"male &&& >=40",
"male &&& >=40"
),
"variable_name" = "number_subjects",
"variable_level" = NA_character_,
"estimate_name" = "count",
"estimate_type" = "integer",
"estimate_value" = c("5", "15", "8", "12"),
"additional_name" = "overall",
"additional_level" = "overall"
) |>
omopgenerics::newSummarisedResult()

# Define mapping to custom new names
names_map <- c(
"acetaminophen" = "Acetamoniphen cohort",
"diclofenac" ="Diclofenac cohort (outdated)",
"ibuprofen" = "Ibuprofen cohort"
)

# Test function
x <- updateColumnValues(
summarised_result = x,
names_map = names_map,
variable = "group_level"
)

check_names <- all(x$group_level %in% unname(names_map))
expect_true(check_names)

})
Loading