R/export.sc_trend.R

Defines functions export.sc_trend

Documented in export.sc_trend

#' @rdname export
#' @export
export.sc_trend <- function(object, 
                            caption = NA, 
                            footnote = NULL, 
                            filename = NA,
                            kable_styling_options = list(), 
                            kable_options = list(), 
                            round = 2,
                            decimals = 2,
                            ...) {
  
  kable_options <- .join_kabel(kable_options)
  kable_styling_options <- .join_kabel_styling(kable_styling_options)
  
  if (is.na(caption)) caption <- c("Trend analysis")
  
  out <- object$trend
  #if (isTRUE(flip)) out <- t(out)
  
  tmp.rownames <- rownames(out)
  rownames(out) <- NULL
  for (tmp in object$formulas) {
    tmp.rownames <- gsub(paste0(tmp, "."), "", tmp.rownames)
  }
  out <- cbind(Phase = tmp.rownames, out)
  
  row_group <- vector("list", length(object$formulas))
  names(row_group) <- object$formulas
  
  for (i in 1:length(object$formulas)) {
    .start <- 1 + (i - 1) * (length(object$design) + 1)
    row_group[[i]] <- .start : (.start + length(object$design))
  }
  
  table <- .create_table(
    out, 
    kable_options, 
    kable_styling_options, 
    caption = caption,
    footnote = footnote,
    row_group = row_group,
    decimals = decimals,
    ...
  )
  
  if (getOption("scan.export.engine") == "kable") {
    for (i in 1:length(object$formulas)) {
      table <- group_rows(
        table, object$formulas[i],
        1 + (i - 1) * (length(object$design) + 1),
        i * (length(object$design) + 1)
        #label_row_css = "text-align: center;"
      )
    }
  }
  # finish ------------------------------------------------------------------
  
  if (!is.na(filename)) .save_export(table, filename)
  table
}
jazznbass/scan documentation built on July 12, 2024, 6:02 p.m.