[R] Knitr: how to find out from within a .Rmd file the output type?

Michal Kvasnička prgosek at gmail.com
Fri Oct 31 12:56:26 CET 2014


Hi.

Is there a way how to find out from within a .Rmd file what output format
is generated?

The reason is this: I write a paper in R markdown in RStudio. Sometimes I
generate .html, sometimes .pdf. My paper presents a table of regression
models using stargazer function. I've got the following code in my paper:

```{r, echo=FALSE, message=FALSE, results='asis'}
model2 <- lm(...)
model3 <- lm(...)
model5 <- lm(...)
stargazer(model2, model3, model5,
          ...,
          type="html")
```

Whenever I change the output format from .html do .pdf, I have to change
the line type="html" to type="latex" manually. (The same holds true for
many other functions, e.g. xtable.)

It would be nice to replace the direct declaration with

      type=some_knitr_variable

What is the true name of the some_knitr_variable? I was not able to find it
anywhere.

Many thanks for your help.

Best wishes,
Michal

	[[alternative HTML version deleted]]



More information about the R-help mailing list