Here is code from notebook:
---
title: "R Notebook"
output:
word_document: default
html_notebook: default
---
```{r}
data(ToothGrowth)
```
```{r}
library(table1)
table1(reformulate(colnames(ToothGrowth)), data=ToothGrowth)
```
```{r}
library(stargazer)
stargazer(ToothGrowth, type = "html")
```
Word file generated with knitr:
R Notebook
data(ToothGrowth)
library(table1)
##
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
##
## units, units<-
table1(reformulate(colnames(ToothGrowth)), data=ToothGrowth)
## [1] "<table class=\"Rtable1\">\n<thead>\n<tr>\n<th class='rowlabel firstrow lastrow'></th>\n<th class='firstrow lastrow'><span class='stratlabel'>Overall<br><span class='stratn'>(n=60)</span></span></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class='rowlabel firstrow'><span class='varlabel'>len</span></td>\n<td class='firstrow'></td>\n</tr>\n<tr>\n<td class='rowlabel'>Mean (SD)</td>\n<td>18.8 (7.65)</td>\n</tr>\n<tr>\n<td class='rowlabel lastrow'>Median [Min, Max]</td>\n<td class='lastrow'>19.3 [4.20, 33.9]</td>\n</tr>\n<tr>\n<td class='rowlabel firstrow'><span class='varlabel'>supp</span></td>\n<td class='firstrow'></td>\n</tr>\n<tr>\n<td class='rowlabel'>OJ</td>\n<td>30 (50.0%)</td>\n</tr>\n<tr>\n<td class='rowlabel lastrow'>VC</td>\n<td class='lastrow'>30 (50.0%)</td>\n</tr>\n<tr>\n<td class='rowlabel firstrow'><span class='varlabel'>dose</span></td>\n<td class='firstrow'></td>\n</tr>\n<tr>\n<td class='rowlabel'>Mean (SD)</td>\n<td>1.17 (0.629)</td>\n</tr>\n<tr>\n<td class='rowlabel lastrow'>Median [Min, Max]</td>\n<td class='lastrow'>1.00 [0.500, 2.00]</td>\n</tr>\n</tbody>\n</table>\n"
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
stargazer(ToothGrowth, type = "html")
##
## <table style="text-align:center"><tr><td colspan="8" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Statistic</td><td>N</td><td>Mean</td><td>St. Dev.</td><td>Min</td><td>Pctl(25)</td><td>Pctl(75)</td><td>Max</td></tr>
## <tr><td colspan="8" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">len</td><td>60</td><td>18.813</td><td>7.649</td><td>4.200</td><td>13.075</td><td>25.275</td><td>33.900</td></tr>
## <tr><td style="text-align:left">dose</td><td>60</td><td>1.167</td><td>0.629</td><td>0.500</td><td>0.500</td><td>2.000</td><td>2.000</td></tr>
## <tr><td colspan="8" style="border-bottom: 1px solid black"></td></tr></table>
Log of word file generation:
processing file: asfdgasdg.Rmd
|........... | 17%
ordinary text without R code
|...................... | 33%
label: unnamed-chunk-1
|................................ | 50%
ordinary text without R code
|........................................... | 67%
label: unnamed-chunk-2
|...................................................... | 83%
ordinary text without R code
|.................................................................| 100%
label: unnamed-chunk-3
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS asfdgasdg.utf8.md --to docx --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash+smart --output asfdgasdg.docx --highlight-style tango
output file: asfdgasdg.knit.md
Output created: asfdgasdg.docx
Also after running code above, html output from Stargazer in RStudio notebook is not rendered html content but just a plain html code. table1 html output is rendered in RStudio notebook, so no problem with it.
If I do I put output of packages in html file and add this file to Word through Insert >> select the file (in html format) >> Insert (at the bottom right corner) >> Insert
, than Word renders html content of those files as word tables (not puts html as plain text.).
My questions:
How to make Stargazer html output to be rendered, not just a plain html code in RStudio notebook?
How to generate Word file with knitr that will give html output of both packages to be shown as word tables, not just plain html code?