File: htmlTable_helpers_prepInputMatrixDimensions.R

package info (click to toggle)
r-cran-htmltable 2.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,600 kB
  • sloc: javascript: 6,797; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 881 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#' Makes sure the input is correct
#'
#' Checks and converts dimensions into something the
#' [htmlTable()] is comfortable with.
#'
#' @inheritParams htmlTable
#' @keywords internal
#' @family hidden helper functions for htmlTable
prPrepInputMatrixDimensions <- function(x, header = NULL) {
  if (!is.null(dim(x))) {
    if (length(dim(x)) != 2) {
      stop(
        "Your table variable seems to have the wrong dimension,",
        " length(dim(x)) = ", length(dim(x)), " != 2"
      )
    }
    return(x)
  }

  preset_styles <- getHtmlTableStyle(x)

  if (!is.numeric(x) && !is.character(x)) {
    x <- as.character(x)
  }

  ncol <- length(x)
  if (!is.null(header)) {
    ncol <- length(header)
  }

  ret <- matrix(x, ncol = ncol)

  # We need to make sures that the style info has been retained throughout
  attr(ret, style_attribute_name) <- preset_styles
  return(ret)
}