How to convert R Markdown to PDF?

Updated Answer (10 Feb 2013) rmarkdown package: There is now an rmarkdown package available on github that interfaces with Pandoc. It includes a render function. The documentation makes it pretty clear how to convert rmarkdown to pdf among a range of other formats. This includes including output formats in the rmarkdown file or running supplying … Read more

Set margin size when converting from Markdown to PDF with pandoc

Recent versions of rmarkdown and pandoc In more recent versions of rmarkdown, the settings of margins can be done in the YAML header via the top-level element geometry. What you specify in the geometry tag will be piped into the LaTeX template that ships with Pandoc via the following LaTeX snippet $if(geometry)$ \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} $endif$ For … Read more

Using stargazer with Rstudio and Knitr

Use the following code and you get a working version “`{r, results=”asis”} stargazer(model) “` When converting to pdf, the following code works perfectly for stargazer 4.0: “`{r, results=”asis”} stargazer(model, header=FALSE, type=”latex”) “`

How to convert R Markdown to HTML? I.e., What does “Knit HTML” do in Rstudio 0.96?

Basic Script So now that the R markdown package has been released, here is some code to replicate the features of Knit to Html. require(knitr) # required for knitting from rmd to md require(markdown) # required for md to html knit(‘test.rmd’, ‘test.md’) # creates md file markdownToHTML(‘test.md’, ‘test.html’) # creates html file browseURL(paste(‘file://’, file.path(getwd(),’test.html’), sep=”)) … Read more

How to use objects from global environment in Rstudio Markdown

For better or worse, this omission is intentional. Relying on objects created outside the document makes your document less reproducible–that is, if your document needs data in the global environment, you can’t just give someone (or yourself in two years) the document and data files and let them recreate it themselves. For this reason, and … Read more

How to set size for local image using knitr for markdown?

The question is old, but still receives a lot of attention. As the existing answers are outdated, here a more up-to-date solution: Resizing local images As of knitr 1.12, there is the function include_graphics. From ?include_graphics (emphasis mine): The major advantage of using this function is that it is portable in the sense that it … Read more

Rstudio rmarkdown: both portrait and landscape layout in a single PDF

So, pandoc does not parse the content of latex environments, but you can fool it by redefining the commands in your header.tex file: \usepackage{lscape} \newcommand{\blandscape}{\begin{landscape}} \newcommand{\elandscape}{\end{landscape}} Thus, here \begin{landscape} is redefined to \blandscape, and \end{landscape} to \elandscape. Using those newly defined command in the .Rmd file seems to work: — title: “Mixing portrait and landscape” … Read more

In `knitr` how can I test for if the output will be PDF or word?

Short Answer In most cases, opts_knit$get(“rmarkdown.pandoc.to”) delivers the required information. Otherwise, query rmarkdown::all_output_formats(knitr::current_input()) and check if the return value contains word_document: if (“word_document” %in% rmarkdown::all_output_formats(knitr::current_input()) { # Word output } Long answer I assume that the source document is RMD because this is the usual/most common input format for knitting to different output formats such … Read more