Skip to content

Instantly share code, notes, and snippets.

@richfitz
Last active December 15, 2015 12:09
Show Gist options
  • Save richfitz/5258213 to your computer and use it in GitHub Desktop.
Save richfitz/5258213 to your computer and use it in GitHub Desktop.
Stargazer, knitr & R markdown
Stargazer and R Markdown to LaTeX
========================================================
If you're using LaTeX, then use the Sweave-like knitr opions here instead. The `results='asis'` means that knitr won't do any processing on the output, so when you run this it produces a bunch of gobbledygook.
```{r}
library(stargazer)
```
```{r, results='asis'}
stargazer(attitude)
```
(oddly, the example in the stargazer vignette is wrong. Boo.)
Running this (Knit HTML) produces an HTML file that looks fine except for the results here. Install Pandoc, and compile the .md file into pdf via LaTeX
You can do this [online](http://johnmacfarlane.net/pandoc/try/) (but only as far as LaTeX), or [install pandoc](http://johnmacfarlane.net/pandoc/) and do it from your computer. But you'll have to install LaTeX and that's a giant hassle.
Alternatively, there are some HTML table packages (e.g. R2HTML, xtable) that might be a better way forward. If markdown is your target document format, you could look at the "[markdown](http://cran.r-project.org/web/packages/markdown)" package to produce markdown tables that will work with the same code as above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment