2 sub("([0-9.-]+)([eE])\\+?(-?)0*([0-9]+)","$\\1\\\\times 10^{\\3\\4}$",
5 to.latex <- function(x){
6 sub("([0-9]+)([eE])\\+?(-?)0*([0-9]+)","\\1\\\\ensuremath{\\\\times 10^{\\3\\4}}",
9 cleanup.tolatex <- function(output) {
10 gsub("\\\\textrm\\{e\\}(-?)0*(\\d+)","\\\\ensuremath{\\\\times 10^{\\1\\2}}",output);
13 trimws <- function(x,left=TRUE,right=TRUE){
16 result <- gsub('^\\s+','',x,perl=TRUE)
18 result <- gsub('\\s+$','',x,perl=TRUE)
24 print.summary.glm.xtable <- function (x, digits = max(3, getOption("digits") - 3), symbolic.cor = x$symbolic.cor, signif.stars = getOption("show.signif.stars"), ...) {
26 cat("\\begin{verbatim}\n")
27 cat("\nCall:\n", paste(deparse(x$call), sep = "\n", collapse = "\n"),
29 cat("Deviance Residuals: \n")
30 if (x$df.residual > 5) {
31 x$deviance.resid <- quantile(x$deviance.resid, na.rm = TRUE)
32 names(x$deviance.resid) <- c("Min", "1Q", "Median", "3Q",
35 xx <- zapsmall(x$deviance.resid, digits + 1)
36 cat("\\end{verbatim}\n")
37 print(table.to.latex(xx,digits=digits))
38 cat("\\begin{verbatim}\n")
39 if (length(x$aliased) == 0L) {
40 cat("\nNo Coefficients\n")
43 df <- if ("df" %in% names(x))
46 if (!is.null(df) && (nsingular <- df[3L] - df[1L]))
47 cat("\nCoefficients: (", nsingular, " not defined because of singularities)\n",
49 else cat("\nCoefficients:\n")
50 coefs <- x$coefficients
51 if (!is.null(aliased <- x$aliased) && any(aliased)) {
53 coefs <- matrix(NA, length(aliased), 4L, dimnames = list(cn,
55 coefs[!aliased, ] <- x$coefficients
57 cat("\\end{verbatim}\n")
58 colnames(coefs) <- gsub("(Pr\\(>\\|z\\|\\))","$\\1$",colnames(coefs),perl=TRUE)
59 if (nrow(coefs) > 15) {
60 print(table.to.latex(coefs,longtable=TRUE))
62 print(table.to.latex(coefs))
64 cat("\\begin{verbatim}\n")
66 cat("\n(Dispersion parameter for ", x$family$family, " family taken to be ",
67 format(x$dispersion), ")\n\n", apply(cbind(paste(format(c("Null",
68 "Residual"), justify = "right"), "deviance:"), format(unlist(x[c("null.deviance",
69 "deviance")]), digits = max(5, digits + 1)), " on",
70 format(unlist(x[c("df.null", "df.residual")])), " degrees of freedom\n"),
71 1L, paste, collapse = " "), sep = "")
72 if (nzchar(mess <- naprint(x$na.action)))
73 cat(" (", mess, ")\n", sep = "")
74 cat("AIC: ", format(x$aic, digits = max(4, digits + 1)),
75 "\n\n", "Number of Fisher Scoring iterations: ", x$iter,
77 correl <- x$correlation
78 if (!is.null(correl)) {
81 cat("\nCorrelation of Coefficients:\n")
82 if (is.logical(symbolic.cor) && symbolic.cor) {
83 print(symnum(correl, abbr.colnames = NULL))
86 correl <- format(round(correl, 2), nsmall = 2,
88 correl[!lower.tri(correl)] <- ""
89 print(correl[-1, -p, drop = FALSE], quote = FALSE)
93 cat("\\end{verbatim}\n")
100 table.to.latex <- function(table,
113 toprule=if(useBooktabs) "\\toprule" else "\\hline\\hline",
114 midrule=if(useBooktabs) "\\midrule" else "\\hline",
115 bottomrule=if(useBooktabs) "\\bottomrule" else "\\hline\\hline",
119 header <- c(if(rownames){""}else{NULL},colnames(table));
120 .format.function <- function(x){
121 format(if(is.null(format)||is.null(scientific)) {x} else {
122 if(!is.na(suppressWarnings(as.numeric(x)))) as.numeric(x) else x},
123 digits=digits,nsmall=nsmall,scientific=scientific,...)
125 if(is.null(dim(table))){
126 header <- names(table)
130 cbind(if(rownames){rownames(table)}else{NULL},
131 if(is.null(dim(table))){t(sapply(table,.format.function))} else
132 {apply(table,1:2,.format.function)}
134 res[,] <- gsub("_","\\\\_",res[,])
135 if (!missing(cols.as.is)) {
138 cbind(if(rownames){rownames(table)}else{NULL},
139 if(is.null(dim(table))){
140 t(sapply(table,function(x){x}))
142 apply(table,1:2,function(x){x})
145 res[,cols.as.is] <- res.no.change[,cols.as.is]
148 coefrows <- 2:NROW(res)
150 coefrows <- 1:NROW(res)
153 ## res[coefrows,ignore.rows] <- sub("(\\*+)","$^{\\1}$",
154 ## res[coefrows,ignore.rows])
156 res[coefrows,ignore.rows] <- sub("([0-9]+)([eE])\\+?(-?)0*([0-9]+)","\\1\\\\ensuremath{\\\\times 10^{\\3\\4}}",
157 res[coefrows,ignore.rows])
159 tabspec <- rep("l",ncol(res))
160 if (length(colspec)==length(tabspec) &&
166 tabbegin <- paste("\\begin{tabular}{",paste(tabspec,collapse=""),"}",sep="")
167 tabend <- "\\end{tabular}\n"
169 tabbegin <- paste("\\begin{longtable}{",paste(tabspec,collapse=""),"}",sep="")
170 tabend <- "\\end{longtable}\n"
171 if (!is.null(label)) {
172 tabend <- paste(sep="","\\label{",label,"}\\\\","\n",
176 if(!is.null(caption))
177 tabend <- paste(sep="","\\caption{",caption,"}\\\\","\n",
180 } else if (!is.null(label)) {
181 tabbegin <- paste0("\\begin{table}",latex.pos,"\n",
182 if (centering) {"\\centering\n"} else {""},
184 if (!is.null(caption)) {
185 tabend <- paste0(tabend,"\\caption{",caption,"}\n")
187 tabend <- paste0(tabend,"\\label{",label,"}\n",
190 ans <- c(ans,tabbegin)
193 header <- c(header,toprule)
195 header <- c(header,paste("\\multicolumn{1}{c}{",gsub("\\_"," ",trimws(res[1,1])),"}",sep=""))
196 for(j in 2:ncol(res))
197 header <- c(header,paste(" & \\multicolumn{1}{c}{",gsub("\\_"," ",trimws(res[1,j])),"}",sep=""))
198 header <- c(header,"\\\\")
200 header <- c(header,midrule)
202 header <- c(header,"\\endhead")
205 for(i in 2:NROW(res)) {
207 paste(paste(res[i,],collapse=" & "),"\\\\"))
210 if(length(bottomrule))
211 ans <- c(ans,bottomrule)
213 structure(ans,class="Latex")