R/print.comp_means.R

Defines functions print.feR.comp_means

Documented in print.feR.comp_means

#' print.feR.comp_means
#'
#' @export
print.feR.comp_means <- function(x){
  # if(class(x) == "data.frame")
  decimals = attr(x,"digits")

  show.markdown.division <- attr(x, "show.markdown.division")
  markdown.division.prefix <- attr(x, "markdown.division.prefix")

  # cat("\n--------1---")
  x$stat.value <- round(x$stat.value,decimals)
  x$stat.ci.low <- round(x$stat.ci.low,decimals)
  x$stat.ci.high <- round(x$stat.ci.high,decimals)
  x$p.exact <- x$p.value

  if (is.numeric(x$p.value)) x$p.value <- round(x$p.value, decimals)

  x$mean.diff <- round(x$mean.diff, decimals)
  x$mean.diff.ci.low <- round(x$mean.diff.ci.low, decimals)
  x$mean.diff.ci.high <- round(x$mean.diff.ci.high, decimals)
  x$var.name <- attr(x,"x.name")
  x$group.var <- attr(x,"y.name")


  # cat("\n--------2---")
  if(!is.null(attr(x,"SHOW.DESCRIPTIVES")) && (attr(x,"SHOW.DESCRIPTIVES"))) print(attr(x,"DESCRIPTIVES"))
  if(!is.null(attr(x,"SHOW.VARIANCE")) && (attr(x,"SHOW.VARIANCE"))) {
    # print(attr(x,"VARIANCE"))
    varianza <- attr(x,"VARIANCE")
    cat("\nVariance comparison method '",varianza$method,"' (p: ",round(varianza$p.value,digits=decimals+1),")\n", sep="")
  }

  # cat("\n--------3---")
  caption = ""
  cont = 1
  for (vn in unique(x$var.name)) {
    # if (caption == "") caption = vn
    if(cont == 1) caption = vn
    else {
      caption <- paste(caption, ifelse(cont == length(unique(x$var.name)),"&",","), vn)
    }

    cont = cont + 1
  }

  caption <- paste(caption, "by")
  cont = 1
  for (vn in unique(x$group.var)) {
    if(cont == 1) caption <- paste(caption, vn)
    else caption <- paste(caption, ifelse(cont == length(unique(x$group.var)),"&",","), vn)
    cont = cont + 1
  }

  # library(tidyr)
  # x.final <- x %>% pivot_longer()
  # print(x.final)


  # cat("\n--------4---")
  for(v in names(x)){
    var.value <- as.character(x[1,v])
    if(exists("stats")) stats <- c(stats,v)
    else stats <- v

    if(exists("r.values")) r.values <- c(r.values,var.value)
    else r.values <- var.value
  }

  x.final <- data.frame(stats=stats, value=r.values)
  # print(x.final)

  if (show.markdown.division) cat("\n", markdown.division.prefix,
                                  " Mean comparison of ",caption,"\n", sep = "")
  # print(knitr::kable(x.final, caption = paste("Mean comparison of",caption)))

  # cat("\n--------5---")
  # print("FER")
  print(knitr::kable(x.final))
}
feranpre/feR documentation built on Nov. 22, 2022, 2:29 a.m.