Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xtable: Changed print method? #17

Open
markmfredrickson opened this issue Dec 1, 2012 · 1 comment
Open

xtable: Changed print method? #17

markmfredrickson opened this issue Dec 1, 2012 · 1 comment

Comments

@markmfredrickson
Copy link
Owner

Looking over the xtable.xbal method, it looks like we are trying to pass special markup options via attributes attached to the return value. These include putting in extra horizontal rows and multicolumn spanning headers that hold the strata names.

In the current version of xtable, using attributes in this way has been replaced in favor of using global options.

Creating contingency tables in this way is a pretty nice feature. I'm working on creating tables for the new group tests, and we'll need these headers again. Also, it would be nice to have multiple row spanning blocks so that we can group variables in the "results" table (let alone some sort of unified table that shows both the variable-by-variable statistics and the group level tests).

Some options:

  • Greatly abuse the row and columns names to include extra information. Eg. colnames(tab) <- c("Strata 1 \\ stat1", " \\ stat2", " \\ stat3", "Strata 2 \\ stat 1", "\\ stat2", "\\ stat3"). We might still have to find some way of making sure xtable doesn't escape our markup.
  • Return an object of class c("xbal_xtable", "xtable", "data.frame") and implement our own print method that sets the appropriate options/arguments and calls print.xtable directly.
  • Skip the highlevel xtable stuff and just spit out our own latex, perhaps using xtable's sanitation functions.
  • Related to the first idea, convert everything to text and just have a bunch of entries that are "". Try to alert users that they need to set include.rownames and include.colunames to FALSE.
  • The Hmisc package provides some latex stuff -- though it seems geared towards generating files rather than inline text generation.

Of these, I think the custom print method is probably the best idea, but I'm certainly open to other solutions.

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin12.2.1 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xtable_1.7-0   testthat_0.7   RItools_0.1-12 abind_1.4-0   

loaded via a namespace (and not attached):
[1] evaluate_0.4.2  grid_2.15.2     lattice_0.20-10 plyr_1.7.1     
[5] SparseM_0.96    stringr_0.6.1   tools_2.15.2   
>  
@benthestatistician
Copy link
Collaborator

Mark, Thanks for catching the change in print.xtable, and thanks for the
excellent survey of options. I share your sense that of these options
growing our own print.xbal_xtable() is the most promising. (Good thinking.)

I vaguely recall being backed into various undesirable kluges and
workarounds when we wrote the existing xtable.xbal method. I wholly
support having all of that replaced with something better. Particularly if
things are now broken, and particularly if the reason that they're broken
is that xtable has been improved in the meantime.

For exporting to latex we decided to tap into xtable's functionality rather
than Hmisc more out of habit and familiarity than anything else. If Hmisc
were to demonstrate some real advantages then I'd be open to re-orienting
ourselves toward it. For our purposes, xtable has the advantage of being
more exclusively devoted to table export purposes; if I'm not mistaken
Hmisc overwrites certain core R functions and method dispatch routines on
load, for instance, something that could create confusion in some RItools
usage scenarios.

I also think we should keep our eyes open for new and newish R packages
that totally reimagine table exporting: both xtable and Hmisc are very old,
15+ years if I'm not mistaken, and my sense is that in recent years there's
been a lot of work done on markup languages that update and improve LaTeX
and html in various ways, eg markdown, mathjax etc, as well as on
translators between these, eg pandoc.
Ben

On Fri, Nov 30, 2012 at 8:52 PM, Mark Fredrickson
[email protected]:

Looking over the xtable.xbal method, it looks like we are trying to pass
special markup options via attributes attached to the return value. These
include putting in extra horizontal rows and multicolumn spanning headers
that hold the strata names.

In the current version of xtable, using attributes in this way has been
replaced in favor of using global options.

Creating contingency tables in this way is a pretty nice feature. I'm
working on creating tables for the new group tests, and we'll need these
headers again. Also, it would be nice to have multiple row spanning blocks
so that we can group variables in the "results" table (let alone some sort
of unified table that shows both the variable-by-variable statistics and
the group level tests).

Some options:

  • Greatly abuse the row and columns names to include extra
    information. Eg. colnames(tab) <- c("Strata 1 \ stat1", " \ stat2",
    " \ stat3", "Strata 2 \ stat 1", "\ stat2", "\ stat3"). We might
    still have to find some way of making sure xtable doesn't escape our markup.
  • Return an object of class c("xbal_xtable", "xtable", "data.frame")and implement our own print method that sets the appropriate
    options/arguments and calls print.xtable directly.
  • Skip the highlevel xtable stuff and just spit out our own latex,
    perhaps using xtable's sanitation functions.
  • Related to the first idea, convert everything to text and just have
    a bunch of entries that are "". Try to alert users that they need to set
    include.rownames and include.colunames to FALSE.
  • The Hmisc package provides some latex stuff -- though it seems
    geared towards generating files rather than inline text generation.

Of these, I think the custom print method is probably the best idea, but
I'm certainly open to other solutions.

sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin12.2.1 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] xtable_1.7-0 testthat_0.7 RItools_0.1-12 abind_1.4-0

loaded via a namespace (and not attached):
[1] evaluate_0.4.2 grid_2.15.2 lattice_0.20-10 plyr_1.7.1
[5] SparseM_0.96 stringr_0.6.1 tools_2.15.2


Reply to this email directly or view it on GitHubhttps://github.com//issues/17.

Ben Hansen
Associate Professor of Statistics, University of Michigan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants