Rstudio knit to PDF

2019-02-17 04:05发布

问题:

The new version of Rstudio (0.98.932) has many new options including knit to PDF. An article describing the new version has a comment from Dave that says:

...after installing rstudio 0.98.932 I don’t get the little dropdown menu for knit-pdf or word when editing a .Rmd file.

I'm having the same issue. A helpful response was posted:

It might be that either:

a) You are not running R 3.0 (which is required for RMarkdown v2); or

b) You have a custom markdown renderer defined (markdownToHTML option). You can check for this by executing:

getOption(“rstudio.markdownToHTML”)

That solved Dave's problem (b), but when I run that command I get NULL

> getOption("rstudio.markdownToHTML")
NULL

Which I assume means I don't have a custom markdown renderer defined. (Previously I did in a cusomized .Rprofile, but I removed that.) My R version is 3.1.0.

Am I misunderstanding the getOption command? Could something else be tripping up my Rstudio?

回答1:

I have just installed the new version of RStudio (0.98.932), which prompted me to upgrade a couple of packages (I can't remember which, although I see I have knitr 1.6, markdown 0.7 and rmarkdown 0.2.46). At first I had the same problem; there was only a single 'knit' option on the tool bar. I managed to get the ability to knit to .pdf by adding the following to the head of my .Rmd file.

---
title: "Sample Document"
output: pdf_document
---

Having done that, I now find I do have a drop down menu with options to knit to HTML, PDF and word. There's also a little gear icon that provides access to the R Markdown document options that wasn't there before. I have no idea what the problem was but it seems OK now!



回答2:

Adding on @nicholas response This is also why I create new .Rmd documents through the RStudio gui

File > New File > R markdown.

This way the YAML header is populated correctly.



标签: r knitr rstudio