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

update g_lineplot with cohort param. #1078

Merged
merged 13 commits into from
Oct 18, 2023
Merged
12 changes: 9 additions & 3 deletions R/g_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#' * `x` (`character`)\cr name of x-axis variable.
#' * `y` (`character`)\cr name of y-axis variable.
#' * `strata` (`character`)\cr name of grouping variable, i.e. treatment arm. Can be `NA` to indicate lack of groups.
#' * `cohort_id` (`character`)\cr name of the variable that identifies group belonging. Only applies if `strata` is
#' not NULL.
#' * `paramcd` (`character`)\cr name of the variable for parameter's code. Used for y-axis label and plot's subtitle.
#' Can be `NA` if `paramcd` is not to be added to the y-axis label or subtitle.
#' * `y_unit` (`character`)\cr name of variable with units of `y`. Used for y-axis label and plot's subtitle.
Expand Down Expand Up @@ -173,6 +175,7 @@ g_lineplot <- function(df,
strata <- NULL # NULL if strata == NA or it is not in variables
} else {
strata <- variables[["strata"]]
cohort_id <- variables[["cohort_id"]]
}
checkmate::assert_flag(y_lab_add_paramcd, null.ok = TRUE)
checkmate::assert_flag(subtitle_add_paramcd, null.ok = TRUE)
Expand Down Expand Up @@ -216,7 +219,7 @@ g_lineplot <- function(df,
if (!is.null(strata) && !is.null(alt_counts_df)) {
strata_N <- paste0(strata, "_N") # nolint

df_N <- as.data.frame(table(alt_counts_df[[strata]], exclude = c(NA, NaN, Inf))) # nolint
df_N <- stats::aggregate(USUBJID ~ eval(parse(text = strata)), data = alt_counts_df, FUN = function(x) length(unique(x))) # nolint
colnames(df_N) <- c(strata, "N") # nolint
df_N[[strata_N]] <- paste0(df_N[[strata]], " (N = ", df_N$N, ")") # nolint

Expand Down Expand Up @@ -471,6 +474,7 @@ h_format_row <- function(x, format, labels = NULL) {
#' @param x (`character`)\cr x variable name.
#' @param y (`character`)\cr y variable name.
#' @param strata (`character` or `NA`)\cr strata variable name.
#' @param cohort_id (`character` or `NA`)\cr variable to identify subjects in cohorts.
#' @param paramcd (`character` or `NA`)\cr `paramcd` variable name.
#' @param y_unit (`character` or `NA`)\cr `y_unit` variable name.
#'
Expand All @@ -481,13 +485,15 @@ h_format_row <- function(x, format, labels = NULL) {
#' control_lineplot_vars(strata = NA)
#'
#' @export
control_lineplot_vars <- function(x = "AVISIT", y = "AVAL", strata = "ARM", paramcd = "PARAMCD", y_unit = "AVALU") {
control_lineplot_vars <- function(x = "AVISIT", y = "AVAL", strata = "ARM", paramcd = "PARAMCD", y_unit = "AVALU",
cohort_id = "USUBJID") {
checkmate::assert_string(x)
checkmate::assert_string(y)
checkmate::assert_string(strata, na.ok = TRUE)
checkmate::assert_string(cohort_id, na.ok = TRUE)
checkmate::assert_string(paramcd, na.ok = TRUE)
checkmate::assert_string(y_unit, na.ok = TRUE)

variables <- c(x = x, y = y, strata = strata, paramcd = paramcd, y_unit = y_unit)
variables <- c(x = x, y = y, strata = strata, paramcd = paramcd, y_unit = y_unit, cohort_id = cohort_id)
return(variables)
}
5 changes: 4 additions & 1 deletion man/control_lineplot_vars.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/g_lineplot.Rd

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