Re: [knitr] Hmisc summary.formula in html markdown

485 visningar
Hoppa till det första olästa meddelandet

Carl Boettiger

oläst,
11 apr. 2013 10:52:502013-04-11
till Dr. Hans Hansen, knitr
hmm, that looks tricky to me.  The "table" is being generated by `print.char.matrix`. `print.summary.formula.reverse` passes print.char.matrix a data frame, which you'd probably want to intercept (means hacking the code out of print.summary.formula?) and convert to a table, so that intelligent tools like xtable or pandoc.table (pander package, if you're using pandoc instead of Rstudio/sundown to render markdown) can make some sense of it (e.g. render as an HTML table when you use the chunk option `results="asis"`).  This is probably more robust but more work.  

Short of that, note that you can modify the layout a bit my passing the options  like `hsep= '|', csep='|', vsep='-'` to summary.formula (see print.char.matrix documentation), and try and coerce the ascii table to look like something the markdown parser can recognize... e.g. that option should look like a table to pandoc or rstudio... 

Here's a whack at that approach, tune as needed. 


```{r results="asis"}
library(Hmisc)
df = data.frame(Age = round(rnorm(100, 50,15)), Sex = rep(c("M", "W")))
out <- summary.formula( ~ Age + Sex, data = df, method = "reverse")
print(out, hsep= '|', csep='|', vsep='-', left.border=FALSE, top.border=FALSE)
```






On Thu, Apr 11, 2013 at 2:12 AM, Dr. Hans Hansen <bea...@gmx.de> wrote:

Hi,

i use summary.formula to make baseline tables and i wonder, whether there is a way to make them "real" html tables in the output file? At the moment they look like ascii-tables in the html-output:

## ## ## Descriptive Statistics (N=100) ## ## +-------+-----------------+ ## | | | ## +-------+-----------------+ ## |Age |38.75/49.00/59.00| ## +-------+-----------------+ ## |Sex : W| 50% (50) | ## +-------+-----------------+



Here's my Code:

```{r}
library(Hmisc)

df = data.frame(Age = round(rnorm(100, 50,15)), Sex = rep(c("M", "W")))
summary.formula( ~ Age + Sex, data = df, method = "reverse")
```

Any hints are appreciated, best, hans

--
You received this message because you are subscribed to the Google Groups "knitr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knitr+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Carl Boettiger
UC Santa Cruz
http://www.carlboettiger.info/

Dr. Hans Hansen

oläst,
18 apr. 2013 08:26:082013-04-18
till kn...@googlegroups.com

Totally forgot about this! Thanks, Carl, i'll have a try! Best, Hans

Tormod Bøe

oläst,
16 feb. 2015 03:07:282015-02-16
till kn...@googlegroups.com
I am updating this old post with something that may be of assistance.

Try the new package moonBook, this gives you a similar table to that using summary.formula, but has better support for html output. It can also be used in companion with ztable by the same author wich has excellent table options and supports markdown.

If you have a large dataset, I recommend the development version of the moonBook package, which has recently been updated to better support this. 

Best regards, 
Tormod

Thell Fowler

oläst,
16 feb. 2015 14:17:132015-02-16
till kn...@googlegroups.com


On Monday, February 16, 2015 at 2:07:28 AM UTC-6, Tormod Bøe wrote:
I am updating this old post with something that may be of assistance.

Try the new package moonBook, this gives you a similar table to that using summary.formula, but has better support for html output. It can also be used in companion with ztable by the same author wich has excellent table options and supports markdown.

If you have a large dataset, I recommend the development version of the moonBook package, which has recently been updated to better support this. 

Best regards, 
Tormod
 


I am looking forward to trying this! Thank you for sharing.

Frank Harrell

oläst,
25 maj 2015 10:02:112015-05-25
till kn...@googlegroups.com, bea...@gmx.de
I have a goal to implement Yihui's suggestions elsewhere so that I can do general latex to html conversion in the Hmisc package using the tth system.  If I can figure out how to set up for proper knitr processing of such generated html things should work.  I have tested this on advanced tables outside knitr and the rendering is pretty amazing.

Frank

Tormod Bøe

oläst,
9 dec. 2015 15:09:322015-12-09
till knitr
Dear Prof. Harrel

Is there any update on this work? Being able to produce html tables from summary.formula would be awesome for us that are usually publishing in journals who do not like latex... (psychology and social science).

Yours sincerely, 
Tormod Bøe

Frank Harrell

oläst,
28 dec. 2015 11:37:082015-12-28
till knitr
It's working fine using TeX4ht's htlatex command:

---
output:
  html_document: default
---
```{r setup}
require(Hmisc)
knitrSet(lang='markdown')
```
```{r summm}
getHdata(pbc)
html(latex(describe(pbc)), rmarkdown=TRUE)
summarym <- summaryM(bili + albumin + stage + protime + sex + age + spiders ~ drug,
                     data=pbc, test=TRUE)
w <- latex(summarym, npct='both', middle.bold=TRUE)
# Use npct='slash' to avoid the use of image files for fractions
html(w, rmarkdown=TRUE)
```
```{r lrm}
require(rms)
getHdata(pbc)
f <- lrm(spiders ~ rcs(age, 4) + rcs(albumin, 3) + sex, data=pbc)
print(f, rmarkdown=TRUE)
```

BUT note that the update to the Hmisc package placed on CRAN last week changed the default for html() from TeX4ht to HeVeA and I haven't checked the approach since then.  HeVeA is much easier to install and MUCH faster than TeX4ht.

Frank
Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden