R/private_prepAlign.R

Defines functions prepAlign

Documented in prepAlign

#' Prepares graph position
#'
#' Prepares the graph position so that it matches the label size
#'
#' @param nc The number of columns
#' @param graph.pos An integer indicating the position of the graph
#' @inheritParams forestplot
#'
#' @return Returns vector of `"l", "c", "r"` values
prepAlign <- function(align, graph.pos, nc) {
  # Prepare the summary and align variables
  if (is.null(align)) {
    if (graph.pos == 1) {
      return(rep("l", nc))
    }

    if (graph.pos == nc + 1) {
      return(c("l", rep("r", nc - 1)))
    }

    return(c("l", rep("c", nc - 1)))
  }

  if (length(align) == 1 &&
      is.character(align) &&
      nchar(align) > 1) {
    align <- strsplit(align, split = "")[[1]]
  }

  if (any(!align %in% c("l", "c", "r"))) {
    stop("The align argument must only contain 'l', 'c', or 'r'. You provided: ", align)
  }
  rep(align, length.out = nc)
}

Try the forestplot package in your browser

Any scripts or data that you put into this service are public.

forestplot documentation built on Aug. 26, 2023, 5:07 p.m.