Skip to content

Commit

Permalink
add MA dummy data and update docs and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Spinner committed Jan 20, 2025
1 parent 4db47a0 commit 686095c
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 29 deletions.
12 changes: 7 additions & 5 deletions R/format_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ format_pkncaconc_data <- function(ADNCA, group_columns, time_column = "AFRLT") {
#'
#' This function creates a pharmacokinetic dose dataset from the provided concentration data.
#'
#' @param ADNCA_conc A data frame containing the concentration data.
#' @param pkncaconc_data A data frame containing the concentration data.
#' @param group_columns A character vector specifying the columns to group by.
#' @param dosno_column A character string specifying the dose number column.
#' @param time_column A character string specifying the time column.
#' @param since_lastdose_time_column A character string specifying the time since last dose column.
#'
#' @returns A data frame containing the dose data.
#'
Expand All @@ -64,8 +68,7 @@ format_pkncadose_data <- function(pkncaconc_data,
group_columns,
dosno_column = NULL,
time_column = "AFRLT",
since_lastdose_time_column = "ARRLT",
nominal_time = "NFRLT") {
since_lastdose_time_column = "ARRLT") {

# Check: Dataset is not empty
if (nrow(pkncaconc_data) == 0) {
Expand All @@ -86,7 +89,7 @@ format_pkncadose_data <- function(pkncaconc_data,
group_columns <- c(group_columns, "TIME")
}

dose_data <- pkncaconc_data %>%
pkncaconc_data %>%
mutate(TIME = !!sym(time_column) - !!sym(since_lastdose_time_column)) %>%
group_by(!!!syms(group_columns)) %>%
arrange(!!sym(since_lastdose_time_column) < 0,
Expand All @@ -95,7 +98,6 @@ format_pkncadose_data <- function(pkncaconc_data,
ungroup() %>%
arrange(!!!syms(group_columns))

dose_data
}

#' Create Dose Intervals Dataset
Expand Down
4 changes: 3 additions & 1 deletion R/general_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#'
#' @param data A data frame containing the ADNCA dataset.
#' @param selected_analytes A character vector of selected analytes to be included in the plot.
#' @param selected_pcspec A character vector of selected pcspec to be included in the plot.
#' @param selected_usubjids A character vector of selected unique subject identifiers (USUBJIDs)
#' to be included in the plot.
#' @param colorby_var A character string specifying the variable by which to color
Expand All @@ -22,7 +23,7 @@
#' @details
#' The function performs the following steps:a
#' \itemize{
#' \item Filters the data based on the selected analytes and subjects.
#' \item Filters the data based on the selected analytes, matrices, and subjects.
#' \item Selects relevant columns and removes rows with missing concentration values.
#' \item Converts 'USUBJID', 'DOSNO', and 'DOSEA' to factors.
#' \item Filters the data by cycle if `time_scale` is "By Cycle".
Expand All @@ -36,6 +37,7 @@
#' # Example usage:
#' plot <- general_lineplot(data = adnca_data,
#' selected_analytes = c("Analyte1", "Analyte2"),
#' selected_pcspec = c("Spec1", "Spec2"),
#' selected_usubjids = c("Subject1", "Subject2"),
#' colorby_var = "DOSNO",
#' time_scale = "By Cycle",
Expand Down
1 change: 1 addition & 0 deletions R/general_meanplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @param data A data frame containing the ADNCA dataset.
#' @param selected_studyids A character vector of selected study IDs to be included in the plot.
#' @param selected_analytes A character vector of selected analytes to be included in the plot.
#' @param selected_pcspecs A character vector of selected pcspecs to be included in the plot.
#' @param selected_cycles A character vector or numeric vector of selected cycles to be
#' included in the plot.
#' @param id_variable A character string specifying the variable by which to color the lines
Expand Down
4 changes: 4 additions & 0 deletions R/lambda_slope_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#' @param conc_pknca_df Data frame containing the concentration data
#' (default is `mydata$conc$data`).
#' @param dosno Numeric value representing the dose number (default is `profile`).
#' @param analyte Character value representing the analyte (default is `analyte`).
#' @param pcspec Character value representing the pcspec (default is `pcspec`).
#' @param usubjid Character value representing the unique subject identifier
#' (default is `patient`).
#' @param R2ADJTHRESHOL Numeric value representing the R-squared adjusted threshold for determining
Expand Down Expand Up @@ -37,6 +39,8 @@
#' # Example usage:
#' plot <- lambda_slope_plot(res_pknca_df = myres$result,
#' conc_pknca_df = mydata$conc$data,
#' analyte = "analyte_1",
#' pcspec = "pcspec_1",
#' dosno = 1,
#' usubjid = "subject_1",
#' R2ADJTHRESHOL = 0.7)
Expand Down
2 changes: 1 addition & 1 deletion inst/shiny/modules/tab_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tab_data_server <- function(id) {
ADNCA <- reactiveVal(
read.csv(
system.file("shiny/data/DummyRO_ADNCA.csv", package = "aNCA"),
# na.strings = c("", "NA")
na.strings = c("", "NA")
)
)

Expand Down
2 changes: 1 addition & 1 deletion inst/shiny/modules/tab_visuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ tab_visuals_ui <- function(id) {
orderInput(
ns("summary_groupby_source"),
"Drag and drop these variables...",
items = c("STUDYID", "USUBJID", "DOSEA",),
items = c("STUDYID", "USUBJID", "DOSEA"),
width = shiny::validateCssUnit("100%"),
connect = ns("summary_groupby")
),
Expand Down
13 changes: 10 additions & 3 deletions man/format_pkncadose_data.Rd

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

5 changes: 4 additions & 1 deletion man/general_lineplot.Rd

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

2 changes: 2 additions & 0 deletions man/general_meanplot.Rd

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

6 changes: 6 additions & 0 deletions man/lambda_slope_plot.Rd

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

7 changes: 6 additions & 1 deletion tests/testthat/test-general_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
sample_data <- data.frame(
STUDYID = rep("Study1", 24),
USUBJID = rep(c("Subject1", "Subject2", "Subject3", "Subject4"), each = 6),
ANALYTE = rep("Analyte1", 24),
ANALYTE = rep(c("Analyte1", "Analyte 2"), each = 12),
PCSPEC = rep(c("Spec1", "Spec2"), each = 12),
DOSNO = rep(1, 24),
EVID = rep(0, 24),
NRRLT = rep(1:6, 4),
Expand All @@ -25,6 +26,7 @@ describe("general_lineplot functions correctly", {
data = sample_data,
selected_analytes = "Analyte1",
selected_usubjids = c("Subject1", "Subject2"),
selected_pcspec = "Spec1",
colorby_var = "DOSNO",
time_scale = "By Cycle",
yaxis_scale = "Linear",
Expand All @@ -39,6 +41,7 @@ describe("general_lineplot functions correctly", {
data = empty_data,
selected_analytes = "Analyte1",
selected_usubjids = c("Subject1", "Subject2"),
selected_pcspec = "Spec1",
colorby_var = "DOSNO",
time_scale = "By Cycle",
yaxis_scale = "Linear",
Expand All @@ -55,6 +58,7 @@ describe("general_lineplot functions correctly", {
data = incomplete_data,
selected_analytes = "Analyte1",
selected_usubjids = c("Subject1", "Subject2"),
selected_pcspec = "Spec1",
colorby_var = "DOSNO",
time_scale = "By Cycle",
yaxis_scale = "Linear",
Expand All @@ -69,6 +73,7 @@ describe("general_lineplot functions correctly", {
data = sample_data,
selected_analytes = "Analyte1",
selected_usubjids = c("Subject1", "Subject2"),
selected_pcspec = "Spec1",
colorby_var = "DOSNO",
time_scale = "By Cycle",
yaxis_scale = "Log",
Expand Down
29 changes: 18 additions & 11 deletions tests/testthat/test-general_meanplot.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Sample data for testing
sample_data <- data.frame(
STUDYID = rep("Study1", 24),
USUBJID = rep(c("Subject1", "Subject2", "Subject3", "Subject4"), each = 6),
ANALYTE = rep("Analyte1", 24),
DOSNO = rep(1, 24),
EVID = rep(0, 24),
NRRLT = rep(1:6, 4),
AVAL = c(
STUDYID = rep("Study1", 48),
USUBJID = rep(c("Subject1", "Subject2", "Subject3", "Subject4"), each = 12),
ANALYTE = rep(c("Analyte1", "Analyte 2"), each = 24),
PCSPEC = rep(c("Spec1", "Spec2"), each = 24),
DOSNO = rep(1, 48),
EVID = rep(0, 48),
NRRLT = rep(1:6, 8),
AVAL = rep(c(
10, 20, 30, 40, 50, 60,
15, 25, 35, 45, 55, 65,
12, 22, 32, 42, 52, 62,
18, 28, 38, 48, 58, 68
),
RRLTU = rep("hours", 24),
AVALU = rep("ng/mL", 24),
DOSEA = rep(35, 24)
), 2),
RRLTU = rep("hours", 48),
AVALU = rep("ng/mL", 48),
DOSEA = rep(35, 48)
)

describe("general_meanplot functions correctly", {
Expand All @@ -23,6 +24,7 @@ describe("general_meanplot functions correctly", {
data = sample_data,
selected_studyids = "Study1",
selected_analytes = "Analyte1",
selected_pcspecs = "Spec1",
selected_cycles = 1
)
expect_s3_class(p, "ggplot")
Expand All @@ -34,6 +36,7 @@ describe("general_meanplot functions correctly", {
data = empty_data,
selected_studyids = "Study1",
selected_analytes = "Analyte1",
selected_pcspecs = "Spec1",
selected_cycles = 1
)
expect_s3_class(p, "ggplot")
Expand All @@ -47,6 +50,7 @@ describe("general_meanplot functions correctly", {
data = incomplete_data,
selected_studyids = "Study1",
selected_analytes = "Analyte1",
selected_pcspecs = "Spec1",
selected_cycles = 1
),
"object 'AVAL' not found"
Expand All @@ -57,6 +61,7 @@ describe("general_meanplot functions correctly", {
data = sample_data,
selected_studyids = "Study1",
selected_analytes = "Analyte1",
selected_pcspecs = "Spec1",
selected_cycles = 1,
plot_sd = TRUE
)
Expand All @@ -72,6 +77,7 @@ describe("general_meanplot functions correctly", {
data = sample_data,
selected_studyids = "Study1",
selected_analytes = "Analyte1",
selected_pcspecs = "Spec1",
selected_cycles = 1,
plot_ci = TRUE
)
Expand All @@ -90,6 +96,7 @@ describe("general_meanplot functions correctly", {
data = sample_data,
selected_studyids = "Study1",
selected_analytes = "Analyte1",
selected_pcspecs = "Spec1",
selected_cycles = 1,
plot_ylog = TRUE
)
Expand Down
Loading

0 comments on commit 686095c

Please sign in to comment.