Skip to content

Commit

Permalink
Merge pull request #3 from Boehringer-Ingelheim/2-align-basic-info-pa…
Browse files Browse the repository at this point in the history
…rameter-with-api-conventions

2 align basic info parameter with api conventions
  • Loading branch information
mattkorb authored Sep 2, 2024
2 parents 82d3e78 + deca33a commit 76be84e
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 91 deletions.
6 changes: 6 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
linters: linters_with_defaults(
line_length_linter(120),
object_usage_linter = NULL,
indentation_linter = NULL,
trailing_whitespace_linter = NULL
)
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dv.clinlines
Title: DaVinci's Clinical Timelines
Version: 1.0.3
Version: 1.0.4
Authors@R:
c(
person("Boehringer-Ingelheim Pharma GmbH & Co.KG", role = c("cph", "fnd")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# dv.clinlines 1.0.4

* Adapt basic_info parameter to adhere module standard

# dv.clinlines 1.0.3

* Initial release of dv.clinlines package to GitHub.
Expand Down
12 changes: 6 additions & 6 deletions R/data_prep.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,21 @@ add_ids <- function(data_list) {
#' @keywords internal
set_basics <- function(data_list, basic_info = default_basic_info(), subjid_var) {
# Extract subject level dataset from data_list
data <- data_list[[basic_info$data]]
data <- data_list[[basic_info$subject_level_dataset_name]]

check_names(
data,
var_names = c(basic_info$trt_start, basic_info$trt_end, basic_info$icf_date),
var_names = c(basic_info$trt_start_var, basic_info$trt_end_var, basic_info$icf_date_var),
subjid_var = subjid_var
)
check_date_type(data, c(basic_info$trt_start, basic_info$trt_end, basic_info$icf_date))
check_date_type(data, c(basic_info$trt_start_var, basic_info$trt_end_var, basic_info$icf_date_var))

return(
list(
data = dplyr::rename(data, dplyr::all_of(c(subject_id = subjid_var))),
trt_start = basic_info$trt_start,
trt_end = basic_info$trt_end,
icf_date = basic_info$icf_date
trt_start = basic_info$trt_start_var,
trt_end = basic_info$trt_end_var,
icf_date = basic_info$icf_date_var
)
)
}
Expand Down
23 changes: 14 additions & 9 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@
#'
#' Helper function to support configuration of a Clinical Timelines module.
#'
#' @param data Character name of the subject level analysis dataset (e.g. "adsl", "dm")
#' @param subject_level_dataset_name Character name of the subject level analysis dataset (e.g. "adsl", "dm")
#' as it is called in the \code{data_list} parameter.
#' @param trt_start Character name of the variable that contains treatment start dates.
#' Must be present in the data frame mentioned in the \code{data} element.
#' @param trt_end Character name of the variable that contains treatment end dates.
#' Must be present in the data frame mentioned in the \code{data} element.
#' @param icf_date Character name of the variable that contains informed consent dates.
#' Must be present in the data frame mentioned in the \code{data} element.
#' @param trt_start_var Character name of the variable that contains treatment start dates.
#' Must be present in the data frame mentioned in the \code{subject_level_dataset_name} element.
#' @param trt_end_var Character name of the variable that contains treatment end dates.
#' Must be present in the data frame mentioned in the \code{subject_level_dataset_name} element.
#' @param icf_date_var Character name of the variable that contains informed consent dates.
#' Must be present in the data frame mentioned in the \code{subject_level_dataset_name} element.
#'
#' @return A list that could directly be used as input for the \code{basic_info} parameter
#' of \code{mod_clinical_timelines()} and \code{mod_clinical_timelines_server()}.
#' @export
#'
set_basic_info <- function(data, trt_start, trt_end, icf_date) {
set_basic_info <- function(subject_level_dataset_name, trt_start_var, trt_end_var, icf_date_var) {
return(
list(data = data, trt_start = trt_start, trt_end = trt_end, icf_date = icf_date)
list(
subject_level_dataset_name = subject_level_dataset_name,
trt_start_var = trt_start_var,
trt_end_var = trt_end_var,
icf_date_var = icf_date_var
)
)
}

Expand Down
8 changes: 4 additions & 4 deletions R/mock_clinical_timelines.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ mock_clinical_timelines_server <- function(input, output, session) {
data_name = shiny::reactive("dummyData"),
data_list,
basic_info = list(
data = "adsl",
trt_start = "TRTSDT",
trt_end = "TRTEDT",
icf_date = "RFICDT"
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
),
mapping = list(
adsl = list(
Expand Down
8 changes: 4 additions & 4 deletions R/mock_with_mm.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mock_with_mm_app <- function() {
"Clinical Timelines" = mod_clinical_timelines(
module_id = "mod1",
basic_info = list(
data = "adsl",
trt_start = "TRTSDT",
trt_end = "TRTEDT",
icf_date = "RFICDT"
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
),
mapping = list(
adsl = list(
Expand Down
16 changes: 12 additions & 4 deletions R/mod_clinical_timelines.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ mod_clinical_timelines_server <- function(module_id,
checkmate::assert_multi_class(data_name, c("reactive", "shinymeta_reactive"), add = ac)
checkmate::assert_multi_class(dataset_list, c("reactive", "shinymeta_reactive"), add = ac)
checkmate::assert_list(basic_info, types = "character", add = ac)
checkmate::assert_subset(names(basic_info), choices = c("data", "trt_start", "trt_end", "icf_date"), add = ac)
checkmate::assert_subset(
names(basic_info),
choices = c(
"subject_level_dataset_name",
"trt_start_var",
"trt_end_var",
"icf_date_var"),
add = ac
)
checkmate::assert_list(mapping, types = "list", add = ac)
checkmate::assert_character(unlist(mapping), add = ac)
lapply(mapping, function(x) {
Expand Down Expand Up @@ -250,8 +258,8 @@ mod_clinical_timelines_server <- function(module_id,
#' A character string that serves as unique identifier for the module.
#' @param basic_info `[list(character(1)+)]`
#'
#' A list of four elements: \code{data}, \code{trt_start},
#' \code{trt_end}, and \code{icf_date}. Assigns the name
#' A list of four elements: \code{subject_level_dataset_name}, \code{trt_start_var},
#' \code{trt_end_var}, and \code{icf_date_var}. Assigns the name
#' of a subject level dataset and column names of treatment start and end, and informed
#' consent variables.
#' @param mapping `[list(list(list(character(1)+)))]`
Expand Down Expand Up @@ -459,7 +467,7 @@ mod_clinical_timelines <- function(module_id,
# afmm$dataset_metadata$name holds the name of the currently selected set of dataset (dv.manager)
data_name = afmm$dataset_metadata$name,
dataset_list = shiny::reactive({
afmm$filtered_dataset()[unique(c(basic_info$data, names(mapping), drug_admin$name))]
afmm$filtered_dataset()[unique(c(basic_info$subject_level_dataset_name, names(mapping), drug_admin$name))]
}),
basic_info = basic_info,
mapping = mapping,
Expand Down
8 changes: 4 additions & 4 deletions R/prep_dummy_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ prep_dummy_data <- function(n = 200) {
default_basic_info <- function() {
return(
set_basic_info(
data = "adsl",
trt_start = "TRTSDT",
trt_end = "TRTEDT",
icf_date = "RFICDT"
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
)
)
}
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ module_list <- list(
"Clinical Timelines" = dv.clinlines::mod_clinical_timelines(
module_id = "mod1",
basic_info = list(
data = "adsl",
trt_start = "TRTSDT",
trt_end = "TRTEDT",
icf_date = "RFICDT"
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
),
mapping = list(
adsl = list(
Expand Down
4 changes: 2 additions & 2 deletions man/mod_clinical_timelines.Rd

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

4 changes: 2 additions & 2 deletions man/mod_clinical_timelines_server.Rd

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

4 changes: 2 additions & 2 deletions man/prep_data.Rd

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

21 changes: 13 additions & 8 deletions man/set_basic_info.Rd

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

4 changes: 2 additions & 2 deletions man/set_basics.Rd

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

8 changes: 4 additions & 4 deletions tests/testthat/apps/bmk_app/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ bmk_server <- function(input, output, session) {
data_name = shiny::reactive("dummyData"),
data_list,
basic_info = list(
data = "adsl",
trt_start = "TRTSDT",
trt_end = "TRTEDT",
icf_date = "RFICDT"
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
),
mapping = list(
adsl = list(
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/apps/large_app/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ data_list <- list(adsl = adsl, adae = adae, exp = exp)
clinlines <- dv.clinlines::mod_clinical_timelines(
module_id = "mod",
basic_info = list(
data = "adsl",
trt_start = "TRTSDT",
trt_end = "TRTEDT",
icf_date = "RFICDT"
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
),
mapping = list(
adsl = list(
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/apps/mm_app/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ dummyData2 <- dv.clinlines:::prep_dummy_data(200) # nolint
clinlines <- dv.clinlines::mod_clinical_timelines(
module_id = "mod",
basic_info = list(
data = "adsl",
trt_start = "TRTSDT",
trt_end = "TRTEDT",
icf_date = "RFICDT"
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
),
mapping = list(
adsl = list(
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-data_prep.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ test_that("set_basics() returns a list with fixed names", {
basic_list <- set_basics(
data_list = list(adsl = df),
basic_info = list(
data = "adsl",
trt_start = "TRTSDT",
trt_end = "TRTEDT",
icf_date = "RFICDT"
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
),
subjid_var = "USUBJID"
)
Expand Down
14 changes: 12 additions & 2 deletions tests/testthat/test-helpers.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Tests for set_basic_info() ----
test_that("set_basic_info() returns a named list", {
outcome <- set_basic_info(data = "adsl", trt_start = "start", trt_end = "end", icf_date = "consent")
expected <- list(data = "adsl", trt_start = "start", trt_end = "end", icf_date = "consent")
outcome <- set_basic_info(
subject_level_dataset_name = "adsl",
trt_start_var = "start",
trt_end_var = "end",
icf_date_var = "consent"
)
expected <- list(
subject_level_dataset_name = "adsl",
trt_start_var = "start",
trt_end_var = "end",
icf_date_var = "consent"
)
expect_equal(outcome, expected)
})

Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/test-prep_dummy_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ test_that("prep_dummy_data() adds a flag for AEREL", {
# Tests for default_basic_info() ----
test_that("default_basic_info() returns a named list with default settings ", {
outcome <- default_basic_info()
expected <- list(data = "adsl", trt_start = "TRTSDT", trt_end = "TRTEDT", icf_date = "RFICDT")
expected <- list(
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
)

expect_equal(outcome, expected)
})
Expand Down
8 changes: 4 additions & 4 deletions vignettes/ae-filter.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ module_list <- list(
"Clinical Timelines" = mod_clinical_timelines(
module_id = "mod1",
basic_info = list(
data = "adsl",
trt_start = "TRTSDT",
trt_end = "TRTEDT",
icf_date = "RFICDT"
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
),
mapping = list(
adsl = list(
Expand Down
Loading

0 comments on commit 76be84e

Please sign in to comment.