From 2f3c6bb1b22c5921011c5a7ee4c785fe0764a8ee Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Mon, 17 Jul 2023 21:41:41 -0400 Subject: [PATCH 1/5] add argument na_name --- R/collect_n_subject.R | 9 ++++++--- man/n_subject.Rd | 11 ++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/R/collect_n_subject.R b/R/collect_n_subject.R index 848ebb9..21aecbd 100644 --- a/R/collect_n_subject.R +++ b/R/collect_n_subject.R @@ -23,6 +23,7 @@ #' @param par A character vector of parameter name. #' @param use_na A character value for whether to include `NA` values #' in the table. See the `useNA` argument in [base::table()] for more details. +#' @param na_name A character value for missing value label, default is "Missing". #' #' @return A data frame summarizing the number of unique subjects #' in different arms. @@ -38,14 +39,16 @@ #' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA) #' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX) #' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, use_na = "always") +#' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, na_name = "Null") n_subject <- function(id, group, par = NULL, - use_na = c("ifany", "no", "always")) { + use_na = c("ifany", "no", "always"), + na_name = "Missing") { use_na <- match.arg(use_na) if ("factor" %in% class(group)) { - u_group <- c(as.character(levels(group)), "Missing") + u_group <- c(as.character(levels(group)), na_name) } else { stop("n_subject: group variable must be a factor") } @@ -61,7 +64,7 @@ n_subject <- function(id, db <- data.frame(id = id, group = group, par = par) res <- table(unique(db)[, c("group", "par")], useNA = use_na) name <- colnames(res) - name[is.na(name)] <- "Missing" + name[is.na(name)] <- na_name n_row <- nrow(res) n_col <- ncol(res) diff --git a/man/n_subject.Rd b/man/n_subject.Rd index bb632f8..57cc6b3 100644 --- a/man/n_subject.Rd +++ b/man/n_subject.Rd @@ -4,7 +4,13 @@ \alias{n_subject} \title{Count number of unique subjects} \usage{ -n_subject(id, group, par = NULL, use_na = c("ifany", "no", "always")) +n_subject( + id, + group, + par = NULL, + use_na = c("ifany", "no", "always"), + na_name = "Missing" +) } \arguments{ \item{id}{A character vector of subject identifier.} @@ -15,6 +21,8 @@ n_subject(id, group, par = NULL, use_na = c("ifany", "no", "always")) \item{use_na}{A character value for whether to include \code{NA} values in the table. See the \code{useNA} argument in \code{\link[base:table]{base::table()}} for more details.} + +\item{na_name}{A character value for missing value label, default is "Missing".} } \value{ A data frame summarizing the number of unique subjects @@ -32,4 +40,5 @@ r2rtf_adae$SEX[1:5] <- NA n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA) n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX) n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, use_na = "always") +n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, na_name = "Null") } From ddf5408b9b292b5d00c1fd6538a28a4ed4de7eed Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Tue, 18 Jul 2023 13:07:48 -0400 Subject: [PATCH 2/5] change documentation --- R/collect_n_subject.R | 9 +++++---- man/n_subject.Rd | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/R/collect_n_subject.R b/R/collect_n_subject.R index 21aecbd..e1251a3 100644 --- a/R/collect_n_subject.R +++ b/R/collect_n_subject.R @@ -21,9 +21,9 @@ #' @param id A character vector of subject identifier. #' @param group A factor vector of group name. #' @param par A character vector of parameter name. +#' @param na A character string used to label missing values. Defaults to `"Missing"`. #' @param use_na A character value for whether to include `NA` values #' in the table. See the `useNA` argument in [base::table()] for more details. -#' @param na_name A character value for missing value label, default is "Missing". #' #' @return A data frame summarizing the number of unique subjects #' in different arms. @@ -39,12 +39,13 @@ #' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA) #' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX) #' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, use_na = "always") -#' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, na_name = "Null") +#' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, na = "Null") n_subject <- function(id, group, par = NULL, - use_na = c("ifany", "no", "always"), - na_name = "Missing") { + na_name = "Missing", + use_na = c("ifany", "no", "always") + ) { use_na <- match.arg(use_na) if ("factor" %in% class(group)) { diff --git a/man/n_subject.Rd b/man/n_subject.Rd index 57cc6b3..2cf1a6d 100644 --- a/man/n_subject.Rd +++ b/man/n_subject.Rd @@ -8,8 +8,8 @@ n_subject( id, group, par = NULL, - use_na = c("ifany", "no", "always"), - na_name = "Missing" + na_name = "Missing", + use_na = c("ifany", "no", "always") ) } \arguments{ @@ -22,7 +22,7 @@ n_subject( \item{use_na}{A character value for whether to include \code{NA} values in the table. See the \code{useNA} argument in \code{\link[base:table]{base::table()}} for more details.} -\item{na_name}{A character value for missing value label, default is "Missing".} +\item{na}{A character string used to label missing values. Defaults to \code{"Missing"}.} } \value{ A data frame summarizing the number of unique subjects @@ -40,5 +40,5 @@ r2rtf_adae$SEX[1:5] <- NA n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA) n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX) n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, use_na = "always") -n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, na_name = "Null") +n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, na = "Null") } From 8bcbdac40706b54b976410ee7757f4fe3e282805 Mon Sep 17 00:00:00 2001 From: wangben718 Date: Tue, 18 Jul 2023 17:09:50 +0000 Subject: [PATCH 3/5] Style code (GHA) --- R/collect_n_subject.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/collect_n_subject.R b/R/collect_n_subject.R index e1251a3..0209ca0 100644 --- a/R/collect_n_subject.R +++ b/R/collect_n_subject.R @@ -44,8 +44,7 @@ n_subject <- function(id, group, par = NULL, na_name = "Missing", - use_na = c("ifany", "no", "always") - ) { + use_na = c("ifany", "no", "always")) { use_na <- match.arg(use_na) if ("factor" %in% class(group)) { From e30dce88cb2f88d08b75d343f94709d1a5b6e2fd Mon Sep 17 00:00:00 2001 From: "Wang, Benjamin" Date: Tue, 18 Jul 2023 13:11:31 -0400 Subject: [PATCH 4/5] change argument name --- R/collect_n_subject.R | 2 +- man/n_subject.Rd | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/collect_n_subject.R b/R/collect_n_subject.R index e1251a3..18331ca 100644 --- a/R/collect_n_subject.R +++ b/R/collect_n_subject.R @@ -43,7 +43,7 @@ n_subject <- function(id, group, par = NULL, - na_name = "Missing", + na = "Missing", use_na = c("ifany", "no", "always") ) { use_na <- match.arg(use_na) diff --git a/man/n_subject.Rd b/man/n_subject.Rd index 2cf1a6d..9c4f8d3 100644 --- a/man/n_subject.Rd +++ b/man/n_subject.Rd @@ -8,7 +8,7 @@ n_subject( id, group, par = NULL, - na_name = "Missing", + na = "Missing", use_na = c("ifany", "no", "always") ) } @@ -19,10 +19,10 @@ n_subject( \item{par}{A character vector of parameter name.} +\item{na}{A character string used to label missing values. Defaults to \code{"Missing"}.} + \item{use_na}{A character value for whether to include \code{NA} values in the table. See the \code{useNA} argument in \code{\link[base:table]{base::table()}} for more details.} - -\item{na}{A character string used to label missing values. Defaults to \code{"Missing"}.} } \value{ A data frame summarizing the number of unique subjects From fde864d07ab6e68348d974960fbb50e59d30f143 Mon Sep 17 00:00:00 2001 From: wangben718 Date: Tue, 18 Jul 2023 17:15:09 +0000 Subject: [PATCH 5/5] Style code (GHA) --- R/collect_n_subject.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/collect_n_subject.R b/R/collect_n_subject.R index e991f11..ea53522 100644 --- a/R/collect_n_subject.R +++ b/R/collect_n_subject.R @@ -44,8 +44,7 @@ n_subject <- function(id, group, par = NULL, na = "Missing", - use_na = c("ifany", "no", "always") - ) { + use_na = c("ifany", "no", "always")) { use_na <- match.arg(use_na) if ("factor" %in% class(group)) {