diff --git a/CHANGELOG.md b/CHANGELOG.md index 39fad066..defd2189 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed `s_kaplan_meier()` range censoring indicator handling to no longer produce `NA` values in the output when either all subjects are censored or none are censored. +- Aligned `a_freq_resp_var_j()` with `a_freq_j()` by adding `.formats` and `na_str` parameters to allow user customization of output formatting and NA string representation (#67). - Export `leftside()`, `postfun_eq5d` and `ac_blank_line` for efficacy templates ### Changed diff --git a/R/a_freq_resp_var_j.R b/R/a_freq_resp_var_j.R index 347559cf..5b173985 100644 --- a/R/a_freq_resp_var_j.R +++ b/R/a_freq_resp_var_j.R @@ -17,6 +17,8 @@ #' @param conf_level (`proportion`)\cr confidence level of the interval. #' @param method (`character`)\cr method for calculating confidence intervals. #' @param weights_method (`character`)\cr method for calculating weights. +#' @param .formats (`character` or NULL)\cr formats to apply to the statistics. If NULL, default formats will be used. +#' @param na_str (`character`)\cr string to use for NA values. Defaults to `rep("NA", 3)`. #' @param ... Additional arguments passed to other functions. #' #' @return Formatted analysis function which is used as `afun` in `analyze_vars()` @@ -68,6 +70,8 @@ a_freq_resp_var_j <- function( "strat_newcombecc" ), weights_method = formals(s_proportion_diff)$weights_method, + .formats = NULL, + na_str = rep("NA", 3), ...) { # ---- Derive statistics: xx / xx (xx.x%) @@ -166,7 +170,9 @@ a_freq_resp_var_j <- function( .stat <- "count_unique_denom_fraction" x_stat <- rslt[[.stat]]$Y - rslt <- rcell(x_stat, format = jjcsformat_count_denom_fraction) + # use .formats if provided, otherwise default to jjcsformat_count_denom_fraction + fmt <- if (is.null(.formats)) jjcsformat_count_denom_fraction else .formats + rslt <- rcell(x_stat, format = fmt) } else { # use the risk differenc function s_rel_risk_val_j on the current level of the incoming variable (.var) # note that the response variable will become .var in the below call @@ -192,10 +198,12 @@ a_freq_resp_var_j <- function( weights_method = weights_method ) x_stat <- rslt[["rr_ci_3d"]]$Y + # use .formats if provided, otherwise default to rr format + fmt <- if (is.null(.formats)) jjcsformat_xx("xx.x (xx.x, xx.x)") else .formats rslt <- rcell( x_stat, - format = jjcsformat_xx("xx.x (xx.x, xx.x)"), - format_na_str = rep("NA", 3) + format = fmt, + format_na_str = na_str ) } diff --git a/man/a_freq_resp_var_j.Rd b/man/a_freq_resp_var_j.Rd index 7ba8f538..c72faa36 100644 --- a/man/a_freq_resp_var_j.Rd +++ b/man/a_freq_resp_var_j.Rd @@ -20,6 +20,8 @@ a_freq_resp_var_j( method = c("wald", "waldcc", "cmh", "ha", "newcombe", "newcombecc", "strat_newcombe", "strat_newcombecc"), weights_method = formals(s_proportion_diff)$weights_method, + .formats = NULL, + na_str = rep("NA", 3), ... ) } @@ -52,6 +54,10 @@ a_freq_resp_var_j( \item{weights_method}{(\code{character})\cr method for calculating weights.} +\item{.formats}{(\code{character} or NULL)\cr formats to apply to the statistics. If NULL, default formats will be used.} + +\item{na_str}{(\code{character})\cr string to use for NA values. Defaults to \code{rep("NA", 3)}.} + \item{...}{Additional arguments passed to other functions.} } \value{