Learn R Programming

HH (version 3.1-47)

latex.array: Generate the latex code for an "array" or "table" with 3, 4, or more dimensions.

Description

Generate the latex code for an "array" or "table" with 3, 4, or more dimensions.

Usage

# S3 method for array
latex(object, ...,
       var.sep = "}\\\\{\\bfseries ", value.sep = ": ",
       use.ndn = TRUE, cgroup = NULL,
       ## rgroup here captures and ignores any incoming rgroup argument
       rgroup = NULL, n.rgroup = NULL,
       title = first.word(deparse(substitute(object))),
       rowlabel=title)

# S3 method for matrix latex(object, ..., use.ndn=TRUE, cgroup=NULL, title=first.word(deparse(substitute(object))), rowlabel=title)

# S3 method for table latex(object, ...) ## prepend c("matrix", "array") to the ## class of the input object, and then call latex.default

Arguments

object

A c("matrix", "array") or "table" object.

Arguments forwarded to the "default" method for latex.

use.ndn

Logical. ndn is an abbreviation for "Names of DimNames". When TRUE (the default), the rowlabel, cgroup, and rgroup values will be taken from the names(dimnames(object)).

rgroup, n.rgroup

These are the standard arguments for latex. Incoming values for rgroup and n.rgroup are ignored by latex.array and replaced with values constructed from the names of the dimnames of the third and higher dimensions of the input array object. Each item in rgroup is assigned the appropriate combination of names(dimnames(object))[-(1:2)].

title, rowlabel, cgroup

These are the standard arguments for latex. When use.ndn is TRUE (the default), then rowlabel is assigned the names(dimnames(object))[1] and cgroup is assigned the names(dimnames(object))[2].

value.sep

When use.ndn is TRUE (the default), and length(dim(object)) >= 3 then this string is used in the constructed rgroup values to separate the factor name from the factor level of the specified dimension, for example ABC: 5.

var.sep

When use.ndn is TRUE (the default), and length(dim(object)) >= 4 then this string is used in the in the constructed rgroup values to separate the name and level of each dimension, for example ABC: 5 ; DEF: 6. The default value is exactly what Hmisc::latex needs in order to place two or more lines (one for each dimension) in boldface.

Value

See latex.

Details

latex.matrix calls latex.default directly. When use.ndn is TRUE (the default), rowlabel and cgroup are constructed from names(dimnames(object)) unless the user explicitly specified them.

latex.array appends all two-dimensional layers object[,, one, at, a, time] into a single long "matrix", ignores any incoming rgroup and n.rgroup (with a warning), and constructs rgroup and n.rgroup to label the layers. When use.ndn is TRUE (the default), rowlabel and cgroup are constructed from names(dimnames(object)) unless the user explicitly specified them.

latex.table prepends c("matrix", "array") to the class of the "table" object, then calls the generic "latex". This step is necessary because the survey package creates objects whose class includes the value "table" but not the values c("matrix", "array"). Should this object be sent directly to latex.default, it would cause on error for any table with dimension larger than two.

See Also

latex

Examples

Run this code
# NOT RUN {
## This sets up the defaults for latex to write to a pdf file
microplot::latexSetOptions()
## It is needed for R CMD check.
## It is recommended if you normally use pdflatex.
## If you want some other destination for latex, use a non-default argument.


  tmp3 <- array(1:8, c(2,2,2),
                list(letters[1:2],
                     letters[3:4],
                     letters[5:6]))

  tmp3

  ltmp3 <- latex(tmp3) ## assignment prevents display of the generated pdf file
                       ## enter the object name to display the file on screen
  ## ltmp3

  ## latex(tmp3) causes a file tmp3.tex to be created in the working directory.
  ## A user might want to keep tmp3.tex and \input{tmp3.tex} it into a longer .tex file.
  ## R CMD check doesn't like tmp3.tex to remain, so it is removed here.
  file.remove("tmp3.tex")

# }
# NOT RUN {
  try(  ## warning: Input rgroup and n.rgroup are ignored
    latex(tmp3, rgroup=letters[1:3], n.rgroup=c(1,1,2), file="ignorergroup.tex")
     )

  names(dimnames(tmp3)) <- LETTERS[24:26]
  latex(tmp3, file="LETTERS3.tex")
  latex(tmp3, rowlabel="Something Else", file="SomethingElse.tex")


  tmp4 <- array(1:120, c(5,4,3,2),
                list(letters[1:5],
                     letters[6:9],
                     letters[10:12],
                     letters[13:14]))

  tmp4
  latex(tmp4, var.sep=" ; ")

  names(dimnames(tmp4)) <- LETTERS[23:26]
  latex(tmp4, file="LETTERS4.tex")

  tmp2 <- array(1:6, c(3,2),
                list(Rows=letters[1:3],
                     Columns=letters[4:5]))

  tmp2

  latex(tmp2)

  ## Input rgroup honored for "matrix"
  latex(tmp2, rgroup=c("Two","One"), n.rgroup=c(2,1), file="rgroup.tex")

  latex(tmp2, rowlabel="something else", file="something.tex")

  ## tableDemo is based on a table constructed from
  ##         survey::svytable(~ FactorA + FactorB + FactorC, Survey.Design.Object)
  tableDemo <- structure(c(28, 25, 33, 12, 6, 22,  8, 12, 23, 24,  6, 32,
                           32, 31, 59, 11, 2, 33, 10,  3, 23,  7,  2, 26),
                         .Dim = c(3L, 4L, 2L),
                         .Dimnames = list(FactorA = c("a", "b", "c"),
                                          FactorB = c("d", "e", "f", "g"),
                                          FactorC = c("h", "i")),
                         class = "table")

  class(tableDemo)
  latex(tableDemo)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab