inserting stargazer or xable table into knitr document
Do you mean something like this (results='asis')?
\documentclass[11pt]{article}
\begin{document}
<<setup, echo = FALSE, results= 'hide', message = FALSE>>=
data(mtcars)
library(ggplot2)
qplot(speed, dist, data = cars) + geom_smooth()
@
<<results='asis'>>=
require(stargazer)
stargazer(mtcars, summary = FALSE)
@
\end{document}
Using stargazer with Rstudio and Knitr
Since the topic has gone a bit stale, I'll assume the issue at hand is to somehow use stargazer with knitr, and not per se the conversion of the stargazer objects into HTML.
Being an avid fan of stargazer, I have come up with the following workflow:
- Write my code in an .Rmd file.
- Knit it into .md. Stargazer tables remain as LaTeX code in the resulting markdown file.
- Use pandoc to convert the markdown file to PDF. Pandoc translates the LaTeX code into proper tables. Alternatively, one can use LyX with knitr plugin to get stargazer tables nicely output in PDF format.
If one wants stargazer tables in MS Word, the best way I have found is to use LaTeX2RTF. Although the very top cells are distorted a bit, fixing it is a matter of removing an erroneous empty cell. For the rest the table is preserved and can be pasted/imported into Word.
These two strategies help use stargazer outside LaTeX. Hope it helps.
Table placement with stargazer and knitr
Starting with version 4.0 (available on CRAN now), you can easily adjust the table placement by using the table.placement argument.
Remove Hashes in R Output from R Markdown and Knitr
You can include in your chunk options something like
comment=NA # to remove all hashes
or
comment='%' # to use a different character
More help on knitr available from here: http://yihui.name/knitr/options
If you are using R Markdown as you mentioned, your chunk could look like this:
```{r comment=NA}
summary(cars)
```
If you want to change this globally, you can include a chunk in your document:
```{r include=FALSE}
knitr::opts_chunk$set(comment = NA)
```
Align multiple tables side by side
Just put two data frames in a list, e.g.
t1 <- head(mtcars)[1:3]
t2 <- head(mtcars)[4:6]
knitr::kable(list(t1, t2))
Note this requires knitr >= 1.13.
Related Topics
How to Install R Packages via Proxy [User + Password]
Labelling the Plots with Images on Graph in Ggplot2
Programming with Ggplot2 and Dplyr
Roracle Not Working in R Studio
Error Connecting to Azure Blob Storage API from R
Independently Move 2 Legends Ggplot2 on a Map
Trouble Installing "Sf" Due to "Gdal"
Forest Plot with Table Ggplot Coding
Nan Is Removed When Using Na.Rm=True
Generate 3 Random Number That Sum to 1 in R
Converting Between Matrix Subscripts and Linear Indices (Like Ind2Sub/Sub2Ind in Matlab)
Math of Tm::Findassocs How Does This Function Work
Running an R Script Using a Windows Shortcut
Plotting Multiple Lines from a Data Frame in R
Stacking an Existing Rasterstack Multiple Times
Making Binned Scatter Plots for Two Variables in Ggplot2 in R