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

Jeff Laake - NOAA Federal jeff.laake at noaa.gov
Fri Oct 31 16:15:56 CET 2014


This has worked for me to choose the type of code to use to create tables
whether it is pdf or hml/word

doc.type <-
strsplit(rmarkdown:::default_output_format("20141014_Regex_Rmarkdown.Rmd")$name,"_")[[1]][1]

where you would use your .rmd filename in place of
20141014_Regex_Rmarkdown.Rmd  I havenb't worked out how to get the
file.nname within the document, so I hardcode it.

--jeff



On Fri, Oct 31, 2014 at 6:21 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
wrote:

> AFAIK markdown is syntactically incompatible with LaTeX, except for math
> mode expressions. That is why we have separate extensions Rmd and Rnw for
> the two types of files. I don't know where one could successfully make use
> of the variable you are asking about.
> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live
> Go...
>                                       Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> On October 31, 2014 4:56:26 AM PDT, "Michal Kvasnička" <prgosek at gmail.com>
> wrote:
> >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]]
> >
> >______________________________________________
> >R-help at r-project.org mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list