Print Math Array
print.xtableMatharray.RdFor an object of class "xtableMatharray", returns the LaTeX
commands to produce an array.
Arguments
- x
An object of class
"xtableMatharray".- print.results
If
TRUE, the generated table is printed to standard output. Set this toFALSEif you will just be using the character vector that is returned invisibly. Default value isTRUE.- format.args
List of arguments for the
formatCfunction. For example, standard German number separators can be specified asformat.args=list(big.mark = "'", decimal.mark = ","). The argumentsdigitsandformatshould not be included in this list. See details for functionprint.xtable. Default value isNULL.- scalebox
If not
NULL, ascaleboxclause will be added around the tabular environment with the specified value used as the scaling factor. Default value isNULL.- comment
If
TRUE, the version and timestamp comment is included. Default value isFALSE.- timestamp
Timestamp to include in LaTeX comment. Set this to
NULLto exclude the timestamp. Default value isNULL.- ...
Additional arguments. (Currently ignored.)
Details
This command prints an array of numbers which may be included in a
mathematical expression in a LaTeX document created using Sweave
or knitr. Internally it calls print.data.frame but with
special values for the arguments, namely that the tabular environment
is array, row names and column names are not included, and there
are no horizontal lines. Note that the default values for the arguments
comment and timestamp are different to the default values
for print.xtable, the justification being that comments would
make the resulting LaTeX harder to read.
Value
A character vector containing the LaTeX code for incorporating an array in a mathematical expression.
Author
David Scott d.scott@auckland.ac.nz.
Examples
V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05,
3.010497e-05, 3.320683e-04, -5.284854e-05,
7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3)
### Simple test of print.xtableMatharray
print.xtableMatharray(xtable(V, display = rep("E", 4)))
#> \begin{array}{rrr}
#> 1.14E-03 & 3.01E-05 & 7.33E-05 \\
#> 3.01E-05 & 3.32E-04 & -5.28E-05 \\
#> 7.33E-05 & -5.28E-05 & 3.52E-04 \\
#> \end{array}
class(V) <- c("xtableMatharray")
class(V)
#> [1] "xtableMatharray"
### Test without any additional arguments
mth <- xtableMatharray(V)
str(mth)
#> Classes ‘xtableMatharray’, ‘xtable’ and 'data.frame': 3 obs. of 3 variables:
#> $ 1: num 1.14e-03 3.01e-05 7.33e-05
#> $ 2: num 3.01e-05 3.32e-04 -5.28e-05
#> $ 3: num 7.33e-05 -5.28e-05 3.52e-04
#> - attr(*, "align")= chr [1:4] "r" "r" "r" "r"
#> - attr(*, "digits")= num [1:4] 0 2 2 2
#> - attr(*, "display")= chr [1:4] "s" "f" "f" "f"
print(mth)
#> \begin{array}{rrr}
#> 0.00 & 0.00 & 0.00 \\
#> 0.00 & 0.00 & -0.00 \\
#> 0.00 & -0.00 & 0.00 \\
#> \end{array}
### Test with arguments to xtable
mth <- xtableMatharray(V, display = rep("E", 4))
str(mth)
#> Classes ‘xtableMatharray’, ‘xtable’ and 'data.frame': 3 obs. of 3 variables:
#> $ 1: num 1.14e-03 3.01e-05 7.33e-05
#> $ 2: num 3.01e-05 3.32e-04 -5.28e-05
#> $ 3: num 7.33e-05 -5.28e-05 3.52e-04
#> - attr(*, "align")= chr [1:4] "r" "r" "r" "r"
#> - attr(*, "digits")= num [1:4] 0 2 2 2
#> - attr(*, "display")= chr [1:4] "E" "E" "E" "E"
print(mth)
#> \begin{array}{rrr}
#> 1.14E-03 & 3.01E-05 & 7.33E-05 \\
#> 3.01E-05 & 3.32E-04 & -5.28E-05 \\
#> 7.33E-05 & -5.28E-05 & 3.52E-04 \\
#> \end{array}
mth <- xtableMatharray(V, digits = 6)
str(mth)
#> Classes ‘xtableMatharray’, ‘xtable’ and 'data.frame': 3 obs. of 3 variables:
#> $ 1: num 1.14e-03 3.01e-05 7.33e-05
#> $ 2: num 3.01e-05 3.32e-04 -5.28e-05
#> $ 3: num 7.33e-05 -5.28e-05 3.52e-04
#> - attr(*, "align")= chr [1:4] "r" "r" "r" "r"
#> - attr(*, "digits")= num [1:4] 6 6 6 6
#> - attr(*, "display")= chr [1:4] "s" "f" "f" "f"
print(mth)
#> \begin{array}{rrr}
#> 0.001140 & 0.000030 & 0.000073 \\
#> 0.000030 & 0.000332 & -0.000053 \\
#> 0.000073 & -0.000053 & 0.000352 \\
#> \end{array}
### Test with additional print.xtableMatharray arguments
mth <- xtableMatharray(V, digits = 6)
str(mth)
#> Classes ‘xtableMatharray’, ‘xtable’ and 'data.frame': 3 obs. of 3 variables:
#> $ 1: num 1.14e-03 3.01e-05 7.33e-05
#> $ 2: num 3.01e-05 3.32e-04 -5.28e-05
#> $ 3: num 7.33e-05 -5.28e-05 3.52e-04
#> - attr(*, "align")= chr [1:4] "r" "r" "r" "r"
#> - attr(*, "digits")= num [1:4] 6 6 6 6
#> - attr(*, "display")= chr [1:4] "s" "f" "f" "f"
print(mth, format.args = list(decimal.mark = ","))
#> \begin{array}{rrr}
#> 0,001140 & 0,000030 & 0,000073 \\
#> 0,000030 & 0,000332 & -0,000053 \\
#> 0,000073 & -0,000053 & 0,000352 \\
#> \end{array}
print(mth, scalebox = 0.5)
#> \scalebox{0.5}{
#> \begin{array}{rrr}
#> 0.001140 & 0.000030 & 0.000073 \\
#> 0.000030 & 0.000332 & -0.000053 \\
#> 0.000073 & -0.000053 & 0.000352 \\
#> \end{array}
#> }
print(mth, comment = TRUE)
#> % latex table generated in R 4.5.1 by xtable 1.8-8 package
#> \begin{array}{rrr}
#> 0.001140 & 0.000030 & 0.000073 \\
#> 0.000030 & 0.000332 & -0.000053 \\
#> 0.000073 & -0.000053 & 0.000352 \\
#> \end{array}
print(mth, timestamp = "2000-01-01")
#> \begin{array}{rrr}
#> 0.001140 & 0.000030 & 0.000073 \\
#> 0.000030 & 0.000332 & -0.000053 \\
#> 0.000073 & -0.000053 & 0.000352 \\
#> \end{array}
print(mth, comment = TRUE, timestamp = "2000-01-01")
#> % latex table generated in R 4.5.1 by xtable 1.8-8 package
#> % 2000-01-01
#> \begin{array}{rrr}
#> 0.001140 & 0.000030 & 0.000073 \\
#> 0.000030 & 0.000332 & -0.000053 \\
#> 0.000073 & -0.000053 & 0.000352 \\
#> \end{array}