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

S3 method for tabular class #161

Merged
merged 4 commits into from
May 8, 2015
Merged

Conversation

RomanTsegelskyi
Copy link
Contributor

S3 method for tabular class as part of the test for GSoC 2015

Given possibly complicated structure of tabular (see example(tabular) for better idea), I decided to add table row names as first columns and highlight them based on emphasize.rownames param.
Also colnames are multiline cells, so the table looks nice when converted using pandoc
For tests, I used the idea, that no matter how underlying implementation of pandoc.table changes, resulting rendering should have the same amount of rows based on data. I think other methods for S3 classes can be tested in similar fashion.

> example(pander.tabular)

pndr.t> pander(tabular(as.factor(am) ~ (mpg+hp+qsec) * (mean+median), data = mtcars), split.tables = Inf)

------------------------------------------------------------------
      \          mpg\      \      hp\      \      qsec\      \    
 as.factor(am)   mean    median   mean   median    mean    median 
--------------- ------- -------- ------ -------- -------- --------
      *0*        17.15    17.3   160.3    175     18.18    17.82  

      *1*        24.39    22.8   126.8    109     17.36    17.02  
------------------------------------------------------------------


pndr.t> pander(tabular( (Species + 1) ~ (n=1) + Format(digits=2)*
pndr.t+ (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ), split.tables = Inf)

------------------------------------------------------------
     \        \    Sepal.Length\    \    Sepal.Width\    \  
  Species     n         mean        sd       mean        sd 
------------ ---- ---------------- ---- --------------- ----
  *setosa*    50        5.01       0.35      3.43       0.38

*versicolor*  50        5.94       0.52      2.77       0.31

*virginica*   50        6.59       0.64      2.97       0.32

   *All*     150        5.84       0.83      3.06       0.44
------------------------------------------------------------


pndr.t> Sex <- factor(sample(c("Male", "Female"), 100, rep=TRUE))

pndr.t> Status <- factor(sample(c("low", "medium", "high"), 100, rep=TRUE))

pndr.t> z <- rnorm(100)+5

pndr.t> fmt <- function(x) {
pndr.t+    s <- format(x, digits=2)
pndr.t+    even <- ((1:length(s)) %% 2) == 0
pndr.t+    s[even] <- sprintf("(%s)", s[even])
pndr.t+    s
pndr.t+ }

pndr.t> tab <- tabular( Justify(c)*Heading()*z*Sex*Heading(Statistic)*Format(fmt())*(mean+sd)
pndr.t+                ~ Status )

pndr.t> pander(tab)

-----------------------------------------------
   \         \        Status\     \       \    
  Sex     Statistic     high     low    medium 
-------- ----------- ---------- ------ --------
*Female*   *mean*       4.76     4.99    4.80  

            *sd*       (0.85)   (1.08)  (1.24) 

 *Male*    *mean*       5.18     5.02    4.59  

            *sd*       (0.90)   (0.88)  (1.19) 
-----------------------------------------------

@coveralls
Copy link

Coverage Status

Coverage increased (+0.33%) to 54.53% when pulling a62c158 on RomanTsegelskyi:tabular into 54a7adf on Rapporter:master.

@daroczig
Copy link
Member

Thank you, this looks extremely promising. Please do not forget to register on Google Melange as part of the official GSoC application.

This was referenced May 8, 2015
daroczig added a commit that referenced this pull request May 8, 2015
@daroczig daroczig merged commit a78386d into Rapporter:master May 8, 2015
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

Successfully merging this pull request may close these issues.

None yet

3 participants