From f4567f2d0e9d7888e9ffe74acea205f046ebe839 Mon Sep 17 00:00:00 2001 From: dscott Date: Tue, 12 Jan 2016 10:41:43 +0000 Subject: [PATCH] Added man/xtableMatharray.Rd. Fixed data commands in OtherPackagesGallery.Rnw git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@91 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- pkg/DESCRIPTION | 2 +- pkg/R/sanitize.R | 2 +- pkg/man/xtable-internal.Rd | 1 - pkg/man/xtableMatharray.Rd | 105 +++++++++++++++++++++++++ pkg/vignettes/OtherPackagesGallery.Rnw | 50 ++++++------ 5 files changed, 132 insertions(+), 28 deletions(-) create mode 100644 pkg/man/xtableMatharray.Rd diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION index 098d922..eabc9e2 100644 --- a/pkg/DESCRIPTION +++ b/pkg/DESCRIPTION @@ -5,7 +5,7 @@ Title: Export Tables to LaTeX or HTML Author: David B. Dahl Maintainer: David Scott Imports: stats, utils -Suggests: knitr, lsmeans, spdep, splm, sphet +Suggests: knitr, lsmeans, spdep, splm, sphet, plm VignetteBuilder: knitr Description: Coerce data to LaTeX and HTML tables. URL: http://xtable.r-forge.r-project.org/ diff --git a/pkg/R/sanitize.R b/pkg/R/sanitize.R index 18c6619..c31a660 100644 --- a/pkg/R/sanitize.R +++ b/pkg/R/sanitize.R @@ -56,7 +56,7 @@ sanitize.numbers <- function(str, type, } else if (math.style.exponents == "UTF8" || math.style.exponents == "UTF-8") { for(i in 1:length(str)) { - ## this code turns 1e5 into 1×10⁵x + ## this code turns 1e5 into a UTF-8 representation of 1\times10^5 if (all(grepl("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$", result[i]))) { temp <- strsplit(result[i],"eE",result[i]) diff --git a/pkg/man/xtable-internal.Rd b/pkg/man/xtable-internal.Rd index 1e0bd4d..671ec83 100644 --- a/pkg/man/xtable-internal.Rd +++ b/pkg/man/xtable-internal.Rd @@ -1,5 +1,4 @@ \name{xtable-internal} -\alias{xtableMatharray} \alias{xtableList} \alias{print.xtableList} \alias{xtableLSMeans} diff --git a/pkg/man/xtableMatharray.Rd b/pkg/man/xtableMatharray.Rd new file mode 100644 index 0000000..c050411 --- /dev/null +++ b/pkg/man/xtableMatharray.Rd @@ -0,0 +1,105 @@ +\name{xtableMatharray} +\alias{xtableMatharray} + +\title{ + Create LaTeX Mathematical Array +} +\description{ + Convert an array of numbers or mathematical expressions into an + \code{xtableMatharray} object so it can be printed. A convenience + function to enable the printing of arrays in mathematical expressions + in LaTeX +} +\usage{ +xtableMatharray(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, auto = FALSE, ...) +} +\arguments{ + \item{x}{A numeric or character matrix.} + \item{caption}{Character vector of length 1 or 2 containing the + table's caption or title. If length is 2, the second item is the + "short caption" used when LaTeX generates a "List of Tables". Set to + \code{NULL} to suppress the caption. Default value is \code{NULL}. + Included here only for consistency with \code{xtable} methods. Not + expected to be of use.} + \item{label}{Character vector of length 1 containing the LaTeX + label. Set to \code{NULL} to suppress the label. + Default value is \code{NULL}. } + \item{align}{Character vector of length equal to the number of columns + of the resulting table, indicating the alignment of the corresponding + columns. Also, \code{"|"} may be used to produce vertical lines + between columns in LaTeX tables, but these are effectively ignored + when considering the required length of the supplied vector. If a + character vector of length one is supplied, it is split as + \code{strsplit(align, "")[[1]]} before processing. Since the row + names are printed in the first column, the length of \code{align} is + one greater than \code{ncol(x)} if \code{x} is a + \code{data.frame}. Use \code{"l"}, \code{"r"}, and \code{"c"} to + denote left, right, and center alignment, respectively. Use + \code{"p{3cm}"} etc. for a LaTeX column of the specified width. For + HTML output the \code{"p"} alignment is interpreted as \code{"l"}, + ignoring the width request. Default depends on the class of + \code{x}. } + \item{digits}{Numeric vector of length equal to one (in which case it + will be replicated as necessary) or to the number of columns of the + resulting table \bold{or} matrix of the same size as the resulting + table, indicating the number of digits to display in the + corresponding columns. Since the row names are printed in the first + column, the length of the vector \code{digits} or the number of + columns of the matrix \code{digits} is one greater than + \code{ncol(x)} if \code{x} is a \code{data.frame}. Default depends + on the class of \code{x}. If values of \code{digits} are negative, + the corresponding values of \code{x} are displayed in scientific + format with \code{abs(digits)} digits.} + \item{display}{ + Character vector of length equal to the number of columns of the + resulting table, indicating the format for the corresponding columns. + Since the row names are printed in the first column, the length of + \code{display} is one greater than \code{ncol(x)} if \code{x} is a + \code{data.frame}. These values are passed to the \code{formatC} + function. Use \code{"d"} (for integers), \code{"f"}, \code{"e"}, + \code{"E"}, \code{"g"}, \code{"G"}, \code{"fg"} (for reals), or + \code{"s"} (for strings). \code{"f"} gives numbers in the usual + \code{xxx.xxx} format; \code{"e"} and \code{"E"} give + \code{n.ddde+nn} or \code{n.dddE+nn} (scientific format); \code{"g"} + and \code{"G"} put \code{x[i]} into scientific format only if it + saves space to do so. \code{"fg"} uses fixed format as \code{"f"}, + but \code{digits} as number of \emph{significant} digits. Note that + this can lead to quite long result strings. Default depends on the + class of \code{x}.} + \item{auto}{ + Logical, indicating whether to apply automatic format when no value + is passed to \code{align}, \code{digits}, or \code{display}. This + \sQuote{autoformat} (based on \code{xalign}, \code{xdigits}, and + \code{xdisplay}) can be useful to quickly format a typical + \code{matrix} or \code{data.frame}. Default value is \code{FALSE}.} + \item{...}{Additional arguments. (Currently ignored.)} +} +\details{ + This function is only usable for production of LaTeX documents, not + HTML. + + Creates an object of class + \code{c("xtableMatharray","xtable","data.frame")}, to ensure that it is + printed by the print method \code{print.xtableMatharray}. +} +\value{ + An object of class \code{c("xtableMatharray","xtable","data.frame")}. +} + +\author{ + David Scott +} +\seealso{ +\code{\link{print.xtableMatharray}} +} +\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) +mth <- xtableMatharray(V) +class(mth) +str(mth) +unclass(mth) +} +\keyword{ print } diff --git a/pkg/vignettes/OtherPackagesGallery.Rnw b/pkg/vignettes/OtherPackagesGallery.Rnw index 30d0e08..145982f 100644 --- a/pkg/vignettes/OtherPackagesGallery.Rnw +++ b/pkg/vignettes/OtherPackagesGallery.Rnw @@ -60,22 +60,22 @@ this section was originally provided by Martin Gubri First load the package and create some objects. <>= library(spdep) -data(oldcol) -COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data = COL.OLD[], +data("oldcol", package = "spdep") +COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data = COL.OLD[], nb2listw(COL.nb)) class(COL.lag.eig) COL.errW.GM <- GMerrorsar(CRIME ~ INC + HOVAL, data = COL.OLD, - nb2listw(COL.nb, style = "W"), + nb2listw(COL.nb, style = "W"), returnHcov = TRUE) class(COL.errW.GM) -COL.lag.stsls <- stsls(CRIME ~ INC + HOVAL, data = COL.OLD, +COL.lag.stsls <- stsls(CRIME ~ INC + HOVAL, data = COL.OLD, nb2listw(COL.nb)) class(COL.lag.stsls) -p1 <- predict(COL.lag.eig, newdata = COL.OLD[45:49,], +p1 <- predict(COL.lag.eig, newdata = COL.OLD[45:49,], listw = nb2listw(COL.nb)) class(p1) -p2 <- predict(COL.lag.eig, newdata = COL.OLD[45:49,], +p2 <- predict(COL.lag.eig, newdata = COL.OLD[45:49,], pred.type = "trend", type = "trend") #type option for retrocompatibility with spdep 0.5-92 class(p2) @@ -93,7 +93,7 @@ class(imp.sim) There is an \code{xtable} method for objects of this type. <>= xtable(COL.lag.eig) -@ %def +@ %def The method for \code{xtable} actually uses the summary of the object, and an identical result is obtained when using the summary of the @@ -119,7 +119,7 @@ print(xtable(COL.lag.eig), booktabs = TRUE) <>= xtable(COL.errW.GM) -@ %def +@ %def \subsubsection{\code{stsls} objects} \label{sec:codestsls-objects} @@ -127,7 +127,7 @@ xtable(COL.errW.GM) <>= xtable(COL.lag.stsls) -@ %def +@ %def \subsubsection{\code{sarlm.pred} objects} \label{sec:codesarlmpred-objects} @@ -136,7 +136,7 @@ xtable(COL.lag.stsls) <>= xtable(p1) -@ %def +@ %def This method transforms the \code{sarlm.pred} objects into data frames, allowing any number of attributes vectors which may vary according to predictor types. @@ -151,12 +151,12 @@ The \code{xtable} method returns the values of direct, indirect and total impact <>= xtable(imp.exact) -@ %def +@ %def \p <>= xtable(imp.sim) -@ %def +@ %def \subsubsection{\code{spautolm} objects} @@ -181,13 +181,13 @@ summary(spautolmOBJECT, Nagelkerke = TRUE) \p <>= class(spautolmOBJECT) -@ %def +@ %def <>= xtable(spautolmOBJECT, display = c("s",rep("f", 3), "e"), digits = 4) -@ %def +@ %def @@ -197,8 +197,8 @@ xtable(spautolmOBJECT, First load the package and create some objects. <>= library(splm) -data(Produc, package = "plm") -data(usaww) +data("Produc", package = "plm") +data("usaww", package = "splm") fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp respatlag <- spml(fm, data = Produc, listw = mat2listw(usaww), model="random", spatial.error="none", lag=TRUE) @@ -217,19 +217,19 @@ class(imp.spml) <>= xtable(respatlag) -@ %def +@ %def \p <>= xtable(GM) -@ %def +@ %def The \code{xtable} method works the same on impacts of \code{splm} models. <>= xtable(imp.spml) -@ %def +@ %def \subsection{The package \pkg{sphet}} \label{sec:package-pkgsphet} @@ -237,10 +237,10 @@ xtable(imp.spml) First load the package and create some objects. <>= library(sphet) -data(columbus) +data("columbus", package = "spdep") listw <- nb2listw(col.gal.nb) -data(coldis) -res.stsls <- stslshac(CRIME ~ HOVAL + INC, data = columbus, listw = listw, +data("coldis", package = "sphet") +res.stsls <- stslshac(CRIME ~ HOVAL + INC, data = columbus, listw = listw, distance = coldis, type = 'Triangular') class(res.stsls) @@ -257,17 +257,17 @@ class(imp.gstsls) <>= xtable(res.stsls) -@ %def +@ %def \p <>= xtable(res.gstsls) -@ %def +@ %def \code{sphet} also provides a method for computing impacts. <>= xtable(imp.gstsls) -@ %def +@ %def \end{document} -- 2.39.5