From de75f314a6f99f931339957832a3a00682cc36ce Mon Sep 17 00:00:00 2001 From: Roman Tsegelskyi Date: Tue, 27 May 2014 10:32:35 +0300 Subject: [PATCH 1/4] Implementation of S3 method for zoo class --- NAMESPACE | 1 + R/S3.R | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index f66b8cb0..cbea7471 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,6 +24,7 @@ S3method(pander,prcomp) S3method(pander,rapport) S3method(pander,table) S3method(pander,CrossTable) +S3method(pander,zoo) export(Pandoc) export(Pandoc.brew) export(Pandoc.convert) diff --git a/R/S3.R b/R/S3.R index aece3ec2..36683027 100644 --- a/R/S3.R +++ b/R/S3.R @@ -426,4 +426,15 @@ pander.CrossTable <- function(x, caption = attr(x, 'caption'), ...){ constructed.table[row.size + 1, ] <- row.last row.names(constructed.table) <- new.row.labels pandoc.table(constructed.table, caption=caption, keep.line.breaks = TRUE, ...) -} \ No newline at end of file +} + +#' @S3method pander zoo +pander.zoo <- function(x, caption = attr(x, 'caption'), ...){ + if (is.null(caption) & !is.null(storage$caption)) + caption <- get.caption() + c.tab <- as.data.frame(t(as.matrix(x))) + colnames(c.tab) <- trunc(time(x)) +# colnames(c.tab) <- format(trunc(time(x)), panderOptions('date')) + rownames(c.tab) <- NULL + pandoc.table(c.tab, caption = caption, ...) +} From 48316861dbe998940f6c0028561a734172bd4d54 Mon Sep 17 00:00:00 2001 From: Roman Tsegelskyi Date: Tue, 27 May 2014 12:31:58 +0300 Subject: [PATCH 2/4] Implementation of S3 method for lme class --- NAMESPACE | 1 + R/S3.R | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index cbea7471..feb40812 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ S3method(pander,htest) S3method(pander,image) S3method(pander,list) S3method(pander,lm) +S3method(pander,lme) S3method(pander,logical) S3method(pander,matrix) S3method(pander,numeric) diff --git a/R/S3.R b/R/S3.R index 36683027..f4090f6c 100644 --- a/R/S3.R +++ b/R/S3.R @@ -438,3 +438,34 @@ pander.zoo <- function(x, caption = attr(x, 'caption'), ...){ rownames(c.tab) <- NULL pandoc.table(c.tab, caption = caption, ...) } + +#' @S3method pander lme +pander.lme <- function(x, caption = attr(x, 'caption'), summary = FALSE, ...) { + + if (is.null(caption)) { + if (is.null(storage$caption)) + caption <- sprintf('Linear mixed-effects model fit by %s : %s', + paste(sub('^[ ]*', '', ifelse(x$method == "REML", "REML\n", "maximum likelihood\n"))), + paste(sub('^[ ]*', '', deparse(x$call$fixed)), collapse = '')) + else + caption <- get.caption() + } + + xs <- summary(x) + res <- as.data.frame(xs$tTable) + + if (summary) { + pandoc.table(res, caption = paste(sub('^[ ]*', 'Fixed effects: ', deparse(x$call$fixed)), collapse = ''), split.tables = Inf,...) + pandoc.table(xs$residuals, caption="Standardized Within-Group Residuals") + pandoc.table(data.frame( + 'Observations' = x$dims[["N"]], + 'Groups' = x$dims$ngrps[1:x$dims$Q], + 'Log-restricted-likelihood' = x$logLik, + check.names = FALSE), keep.trailing.zeros = TRUE, caption = caption, digits = 4) + } else { + + pandoc.table(res, caption = caption, ...) + + } + +} From a5045bc0589770792f9312dc8906a413083cfc56 Mon Sep 17 00:00:00 2001 From: Roman Tsegelskyi Date: Sat, 31 May 2014 14:45:41 +0300 Subject: [PATCH 3/4] Fixed a type. Deleted zoo branch from here --- NAMESPACE | 1 - R/S3.R | 13 +------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index feb40812..6e72565e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,7 +25,6 @@ S3method(pander,prcomp) S3method(pander,rapport) S3method(pander,table) S3method(pander,CrossTable) -S3method(pander,zoo) export(Pandoc) export(Pandoc.brew) export(Pandoc.convert) diff --git a/R/S3.R b/R/S3.R index f4090f6c..ad1edace 100644 --- a/R/S3.R +++ b/R/S3.R @@ -428,24 +428,13 @@ pander.CrossTable <- function(x, caption = attr(x, 'caption'), ...){ pandoc.table(constructed.table, caption=caption, keep.line.breaks = TRUE, ...) } -#' @S3method pander zoo -pander.zoo <- function(x, caption = attr(x, 'caption'), ...){ - if (is.null(caption) & !is.null(storage$caption)) - caption <- get.caption() - c.tab <- as.data.frame(t(as.matrix(x))) - colnames(c.tab) <- trunc(time(x)) -# colnames(c.tab) <- format(trunc(time(x)), panderOptions('date')) - rownames(c.tab) <- NULL - pandoc.table(c.tab, caption = caption, ...) -} - #' @S3method pander lme pander.lme <- function(x, caption = attr(x, 'caption'), summary = FALSE, ...) { if (is.null(caption)) { if (is.null(storage$caption)) caption <- sprintf('Linear mixed-effects model fit by %s : %s', - paste(sub('^[ ]*', '', ifelse(x$method == "REML", "REML\n", "maximum likelihood\n"))), + paste(sub('^[ ]*', '', ifelse(x$method == "REML", "REML", "maximum likelihood\n"))), paste(sub('^[ ]*', '', deparse(x$call$fixed)), collapse = '')) else caption <- get.caption() From 784ca3cfd52acda8608d361bfb7a36e65c44af00 Mon Sep 17 00:00:00 2001 From: Roman Tsegelskyi Date: Sun, 1 Jun 2014 18:59:06 +0300 Subject: [PATCH 4/4] Fixed unnecessary linebreak for ML method --- R/S3.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/S3.R b/R/S3.R index ad1edace..66aaf99c 100644 --- a/R/S3.R +++ b/R/S3.R @@ -434,7 +434,7 @@ pander.lme <- function(x, caption = attr(x, 'caption'), summary = FALSE, ...) { if (is.null(caption)) { if (is.null(storage$caption)) caption <- sprintf('Linear mixed-effects model fit by %s : %s', - paste(sub('^[ ]*', '', ifelse(x$method == "REML", "REML", "maximum likelihood\n"))), + paste(sub('^[ ]*', '', ifelse(x$method == "REML", "REML", "maximum likelihood"))), paste(sub('^[ ]*', '', deparse(x$call$fixed)), collapse = '')) else caption <- get.caption()