Skip to content

Commit

Permalink
enable flexibility to display "number of xxx" row (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
elong0527 committed Nov 15, 2023
1 parent ea8ef57 commit 2bf59e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions R/metalite_table1.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' @param id a character value to indicate subject/record id variable name in `data`.
#' @param var_listing a character vector of additional variables included in the drill down listing.
#' @param total a logical value to display or hide "Total" column.
#' @param header a logical vector with length 1 or same length of the variables in `formula` to show the `Number of xxx` row of each variable.
#' Default is to show the row for the first variable.
#' @param download a character value to enable download button. Allowed values include
#' "none", "listing", "table", and 'all'.
#' @param type a character value to control section title (e.g. "Subjects", "Records").
Expand All @@ -24,14 +26,14 @@ metalite_table1 <- function(formula,
id,
var_listing = NULL,
total = TRUE,
header = NULL,
download = "none",
type = NULL,
...) {
if (nrow(data) == 0) {
stop("There is no records in the input dataset")
}


if (formula[[2]][[1]] == "|") {
var <- all.vars(formula[[2]][[2]])
group <- all.vars(formula[[2]][[3]])
Expand All @@ -42,6 +44,10 @@ metalite_table1 <- function(formula,
group <- "group"
}

if(! length(header) %in% c(0, 1, length(var))){
stop("The length of `header` should be either 1 or the same number of variables")
}

data[[group]] <- factor(data[[group]])

var_label <- metalite::get_label(data)[var]
Expand All @@ -55,8 +61,12 @@ metalite_table1 <- function(formula,
...
)

plan$column_header <- FALSE
plan$column_header[1] <- TRUE
if(is.null(header)){
plan$column_header <- FALSE
plan$column_header[1] <- TRUE
}else{
plan$column_header <- header
}

plan$keep_total <- plan$column_header

Expand Down
4 changes: 4 additions & 0 deletions man/metalite_table1.Rd

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

0 comments on commit 2bf59e4

Please sign in to comment.