Skip to content

Commit

Permalink
drop rms::mtable support for now
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Aug 4, 2017
1 parent 3e8cbf3 commit 490bea0
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 144 deletions.
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ S3method(pander,lrm)
S3method(pander,manova)
S3method(pander,matrix)
S3method(pander,microbenchmark)
S3method(pander,mtable)
S3method(pander,name)
S3method(pander,nls)
S3method(pander,numeric)
Expand Down Expand Up @@ -159,7 +158,6 @@ importFrom(stats,coef)
importFrom(stats,cycle)
importFrom(stats,end)
importFrom(stats,frequency)
importFrom(stats,ftable)
importFrom(stats,naprint)
importFrom(stats,pchisq)
importFrom(stats,pt)
Expand Down
5 changes: 4 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ Fixes:
* `keep.trailing.zeros` regression bug (#259)
* `pandoc.formula` with caption (#274)
* show estimes of `htest` (#277)
* `rms` update 0.5 fixes on `reVector` to `reListclean`
* `rms` update 0.5 fixes on `reVector` to `reListclean`

New classes supported by the `pander` generic S3 method:
* ets (#231)
* data.table (#241)

Classes no longer supported by the `pander` generic S3 method:
* due to the major updates in the `memisc` package, for at least temporarily, we have removed `mtable` support

pander 0.6.0 (2015-10-27)
----------------------------------------------------------------

Expand Down
95 changes: 0 additions & 95 deletions R/S3.R
Original file line number Diff line number Diff line change
Expand Up @@ -804,101 +804,6 @@ pander.ftable <- function(x, ...)
pandoc.table(x, ...)


#' Pander method for mtable class
#'
#' Prints a mtable object in Pandoc's markdown.
#' @param x a mtable object
#' @param caption caption (string) to be shown under the table
#' @param ... optional parameters passed to raw \code{pandoc.table} function
#' @export
#' @importFrom stats ftable
pander.mtable <- function(x, caption = attr(x, 'caption'),
...
){

if (is.null(caption) & !is.null(storage$caption)) {
caption <- get.caption()
}

coefs <- x$coefficients
summaries <- x$summaries

coef.dims <- lapply(coefs, dim)
coef.ldim <- sapply(coef.dims, length)
max.coef.ldim <- max(coef.ldim)

coef.dims1 <- unique(sapply(coef.dims, '[[', 1))
stopifnot(length(coef.dims1) == 1)

grp.coefs <- max.coef.ldim > 3
if (grp.coefs){
coef.dims4 <- sapply(coef.dims[coef.ldim > 3], '[', 4)
grp.coefs <- grp.coefs && any(coef.dims4 > 1)
}

coef.names <- dimnames(coefs[[1]])[[3]]

mtab <- character()

frmt1 <- function(name, coefs, summaries){

coef.tab <- coefs
dm <- dim(coefs)
if (length(dm) == 3) dm <- c(dm, 1)
dim(coef.tab) <- dm

if (dm[1] > 1){
coef.tab <- apply(coef.tab, 2:4, paste, collapse = '\\ \n')
} else {
coef.tab <- apply(coef.tab, c(1, 3:4), paste, collapse = ' ')
}

dim(coef.tab) <- dim(coef.tab)[-1]

if (grp.coefs){
hdr <- character(ncol(coef.tab))
if (length(dim(coefs)) > 3){
if (dm[4] > 1)
eq.names <- dimnames(coefs)[[4]]
else
eq.names <- ''
ii <- seq(from = 1, length = dm[4], by = dm[2])
hdr[ii] <- eq.names
}
coef.tab <- rbind(hdr, coef.tab)
}
hdr <- character(ncol(coef.tab))
hdr[1] <- name
coef.tab <- rbind(hdr, coef.tab)
if (length(summaries)){
sum.tab <- matrix('', nrow = length(summaries), ncol = ncol(coef.tab))
sum.tab[, 1] <- summaries
coef.tab <- rbind(coef.tab, sum.tab)
}
coef.tab
}

for (i in 1:length(coefs)) {
mtab <- cbind(mtab, frmt1(names(coefs)[i], coefs[[i]], summaries[, i]))
}

colnames(mtab) <- mtab[1, ]
mtab <- mtab[-1,, drop = FALSE] #nolint

ldr <- coef.names

hldr <- NULL
if (grp.coefs)
hldr <- c(hldr, '')
if (length(x$model.groups))
hldr <- c('', hldr)
ldr <- c(hldr, ldr, rownames(summaries))

rownames(mtab) <- ldr

pandoc.table(mtab, caption = caption, keep.line.breaks = TRUE, ...)
}

#' Pander method for CrossTable class
#'
#' Prints a CrossTable object in Pandoc's markdown.
Expand Down
28 changes: 0 additions & 28 deletions inst/tests/test-S3.R
Original file line number Diff line number Diff line change
Expand Up @@ -740,34 +740,6 @@ test_that('pander.aovlist/pander.summary.aovlist behaves correctly', {
expect_equal(length(pa), 14)
})

test_that('pander.mtable behaves correctly', {
suppressMessages(require(memisc))
lm0 <- lm(sr ~ pop15 + pop75, data = LifeCycleSavings)
pm <- pander_return(memisc::mtable(lm0), style = 'grid') # produces 2 columns, corner case
expect_equal(length(strsplit(pm[3], '\\+')[[1]]), 3)
expect_equal(length(pm), 35)

berkeley <- Aggregate(Table(Admit, Freq)~., data = UCBAdmissions)
berk0 <- glm(cbind(Admitted, Rejected)~1, data = berkeley, family = 'binomial')
berk1 <- glm(cbind(Admitted, Rejected)~Gender, data = berkeley, family = 'binomial')
berk2 <- glm(cbind(Admitted, Rejected)~Gender + Dept, data = berkeley, family = 'binomial')
pm <- pander_return(mtable(berk0, summary.stats = NULL), style = 'grid') # only one row
expect_equal(length(pm), 9)
# horizontal, produced an error before
x <- memisc::mtable(berk0, berk1, berk2,
coef.style = 'horizontal',
summary.stats = c('Deviance', 'AIC', 'N'))
pm <- pander_return(x, style = 'grid', split.tables = Inf)
expect_equal(length(pm), 26)
expect_true(all(sapply(colnames(x$coeficient), grepl, pm[4])))

# more complex mtable
pm <- pander_return(memisc::mtable(berk0, berk1, berk2,
coef.style = 'all',
summary.stats = c('Deviance', 'AIC', 'N')), style = 'grid')
expect_equal(length(pm), 47)
})

test_that('pander.ts behaves correctly', {
# ncol NULL
res <- pander_return(ts(1:10, frequency = 4, start = c(1959, 2)), style = 'simple')
Expand Down
18 changes: 0 additions & 18 deletions man/pander.mtable.Rd

This file was deleted.

0 comments on commit 490bea0

Please sign in to comment.