FreesearchR/R/baseline_table.R

23 lines
619 B
R
Raw Normal View History

2024-11-08 15:13:33 +01:00
#' Print a flexible baseline characteristics table
#'
#' @param data data set
#' @param fun.args list of arguments passed to
#' @param fun function to
#' @param vars character vector of variables to include
#'
#' @return object of standard class for fun
#' @export
#'
#' @examples
#' mtcars |> baseline_table()
#' mtcars |> baseline_table(fun.args = list(by = "gear"))
baseline_table <- function(data, fun.args = NULL, fun = gtsummary::tbl_summary, vars = NULL) {
if (!is.null(vars)) {
data <- data |> dplyr::select(dplyr::all_of(vars))
2024-11-08 15:13:33 +01:00
}
out <- do.call(fun, c(list(data = data), fun.args))
return(out)
}