i working stargazer
, want produce latex
output simple lm
object. problem cannot set align = true
without getting error.
latex error: \caption outside float.
i checked , message says wrong. copying stargazer
output directly latex document works fine. copying rmarkdown
document produces same error (which no surprise wanted sure). after playing around bit figured out working in rmarkdown
if significance stars(*) removed (or precise ^{***}
). however, stargazer
producing them default , important part of output.
is there way make work?
--- header-includes: - \usepackage{dcolumn} output: pdf_document --- ## r markdown ```{r, include = false} library(stargazer) df <- data.frame(x = 1:10 + rnorm(100), y = 1:10 + rnorm(100)) reg <- lm(y ~ x, data = df) ``` ```{r, results='asis', echo = false} stargazer(reg, header = false, align = true) ```
on linux systems, wrapping stargazer inside either invisible
or suppressmessages
works suppress garbage otherwise gets rendered. unfortunately, solution not seem work on windows computers.
--- header-includes: - \usepackage{dcolumn} output: pdf_document --- ## r markdown ```{r, include = false} library(stargazer) df <- data.frame(x = 1:10 + rnorm(100), y = 1:10 + rnorm(100)) reg <- lm(y ~ x, data = df) ``` ```{r, results='asis', echo = false} invisible(stargazer(reg, header = false, align = true)) # suppressmessages(stargazer(reg, header = false, align = true)) # works ```
the reason (from page)
stargazer uses cat() output latex/html code or ascii text table. allow further processing of output, stargazer returns same output invisibly character vector.
we use suppressmessages
or invisible
ensure first output (produced cat) rendered. character vector output turns garbage when rmarkdown attempts render using print
, rather cat
Comments
Post a Comment