From fa4bf1b7c2fe9506aec8bdddd72afefd6c2f827f Mon Sep 17 00:00:00 2001 From: dscott Date: Tue, 5 Jan 2016 05:54:15 +0000 Subject: [PATCH] Code to produce tables for objects from spatial econometrics packages added git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@79 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- pkg/DESCRIPTION | 2 +- pkg/NAMESPACE | 11 +++++ pkg/NEWS | 5 ++- pkg/R/xtable.R | 101 ++++++++++++++++++++++++++++++++++++++++++++++ pkg/man/xtable.Rd | 14 ++++++- 5 files changed, 130 insertions(+), 3 deletions(-) diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION index 13199e9..6c34678 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 +Suggests: knitr, lsmeans, spdep, splm, sphet VignetteBuilder: knitr Description: Coerce data to LaTeX and HTML tables. URL: http://xtable.r-forge.r-project.org/ diff --git a/pkg/NAMESPACE b/pkg/NAMESPACE index e316a48..7b559b0 100644 --- a/pkg/NAMESPACE +++ b/pkg/NAMESPACE @@ -43,3 +43,14 @@ S3method("xtable", "summary.prcomp") S3method("xtable", "coxph") S3method("xtable", "ts") S3method("xtable", "zoo") +S3method("xtable", "sarlm") +S3method("xtable", "summary.sarlm") +S3method("xtable", "gmsar") +S3method("xtable", "summary.gmsar") +S3method("xtable", "stsls") +S3method("xtable", "summary.stsls") +S3method("xtable", "splm") +S3method("xtable", "summary.splm") +S3method("xtable", "sphet") +S3method("xtable", "summary.sphet") + diff --git a/pkg/NEWS b/pkg/NEWS index 2def7fb..7228e64 100644 --- a/pkg/NEWS +++ b/pkg/NEWS @@ -3,7 +3,10 @@ LaTeX code to enable an array to be included in a document. * added example to the gallery using sanitizing headings and row names to produce large bold headings and italic row names. - + * added code from Martin Gubri, martin.gubri@framasoft.org, to produce + tables from the spatial econometrics packages, spdep, splm, and + sphet. + 1.8-0 * autoformat, xalign, xdigits, xdisplay from Arni Magnusson, added along with help file. Feature request #5686. diff --git a/pkg/R/xtable.R b/pkg/R/xtable.R index f46da90..65473da 100644 --- a/pkg/R/xtable.R +++ b/pkg/R/xtable.R @@ -306,3 +306,104 @@ xtable.zoo <- function(x, ...) { } +### package spdep +### sarlm objects +xtable.sarlm <- function(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, auto = FALSE, ...) { + return(xtable.summary.sarlm(summary(x), caption = caption, label = label, + align = align, digits = digits, + display = display, auto = auto)) +} + +xtable.summary.sarlm <- function(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, auto = FALSE, + ...) { + x <- data.frame(x$Coef, check.names = FALSE) + + class(x) <- c("xtable","data.frame") + caption(x) <- caption + label(x) <- label + if(auto && is.null(align)) align <- xalign(x) + if(auto && is.null(digits)) digits <- xdigits(x) + if(auto && is.null(display)) display <- xdisplay(x) + align(x) <- switch(1+is.null(align), align, c("r","r","r","r","r")) + digits(x) <- switch(1+is.null(digits), digits, c(0,4,4,2,4)) + display(x) <- switch(1+is.null(display), display, c("s","f","f","f","f")) + return(x) +} + +### gmsar objects +xtable.gmsar <- function(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, auto = FALSE, ...) { + return(xtable.summary.sarlm(summary(x), caption = caption, label = label, + align = align, digits = digits, + display = display, auto = auto)) +} + +xtable.summary.gmsar <- function(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, + auto = FALSE, ...) { + return(xtable.summary.sarlm(x, caption = caption, label = label, + align = align, digits = digits, + display = display, auto = auto)) +} + +### stsls objects +xtable.stsls <- function(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, auto = FALSE, ...) { + return(xtable.summary.sarlm(summary(x), caption = caption, label = label, + align = align, digits = digits, + display = display, auto = auto)) +} + +xtable.summary.stsls <- function(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, + auto = FALSE, ...) { + return(xtable.summary.sarlm(x, caption = caption, label = label, + align = align, digits = digits, + display = display, auto = auto)) +} + + +### package splm +### splm objects +xtable.splm <- function(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, auto = FALSE, ...) { + return(xtable.summary.splm(summary(x), caption = caption, label = label, + align = align, digits = digits, + display = display, auto = auto)) +} + +xtable.summary.splm <- function(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, auto = FALSE, + ...) { + x <- data.frame(x$CoefTable, check.names = FALSE) + + class(x) <- c("xtable","data.frame") + caption(x) <- caption + label(x) <- label + if(auto && is.null(align)) align <- xalign(x) + if(auto && is.null(digits)) digits <- xdigits(x) + if(auto && is.null(display)) display <- xdisplay(x) + align(x) <- switch(1+is.null(align), align, c("r","r","r","r","r")) + digits(x) <- switch(1+is.null(digits), digits, c(0,4,4,2,4)) + display(x) <- switch(1+is.null(display), display, c("s","f","f","f","f")) + return(x) +} + +### package sphet +### sphet objects +xtable.sphet <- function(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, auto = FALSE, ...) { + return(xtable.summary.splm(summary(x), caption = caption, label = label, + align = align, digits = digits, + display = display, auto = auto)) +} + +xtable.summary.sphet <- function(x, caption = NULL, label = NULL, align = NULL, + digits = NULL, display = NULL, + auto = FALSE, ...) { + return(xtable.summary.splm(x, caption = caption, label = label, + align = align, digits = digits, + display = display, auto = auto)) +} diff --git a/pkg/man/xtable.Rd b/pkg/man/xtable.Rd index f6a5af5..50f6a77 100644 --- a/pkg/man/xtable.Rd +++ b/pkg/man/xtable.Rd @@ -18,7 +18,19 @@ \alias{xtable.ts} \alias{xtable.table} \alias{xtable.zoo} -\alias{xtable.xtableList} +\alias{xtable.sarlm} +\alias{xtable.summary.sarlm} +\alias{xtable.gmsar} +\alias{xtable.summary.gmsar} +\alias{xtable.stsls} +\alias{xtable.summary.stsls} +\alias{xtable.splm} +\alias{xtable.summary.splm} +\alias{xtable.sphet} +\alias{xtable.summary.sphet} + + + \title{Create Export Tables} \description{ Convert an R object to an \code{xtable} object, which can -- 2.39.2