Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R markdown compile error:

When I try to compile an Rmarkdown document to pdf, I get this error:

    Error: Functions that produce HTML output found in document targeting latex output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:

  always_allow_html: yes

Note however that the HTML output will not be visible in non-HTML formats.

Does anyone know what this means?

like image 384
wolfsatthedoor Avatar asked Mar 01 '17 22:03

wolfsatthedoor


People also ask

How do I compile in Markdown in R?

The usual way to compile an R Markdown document is to click the Knit button as shown in Figure 2.1, and the corresponding keyboard shortcut is Ctrl + Shift + K ( Cmd + Shift + K on macOS). Under the hood, RStudio calls the function rmarkdown::render() to render the document in a new R session.

Why is my R Markdown file not knitting?

No Knit HTML button This means that RStudio doesn't understand your document is supposed to be an RMarkdown document, often because your file extension is . txt . To fix this, go to the Files tab (lower right corner, same pane as Plots and Help) and select the checkbox next to your document's name.

How do I ignore an error in R?

The simplest way of handling conditions in R is to simply ignore them: Ignore errors with try() . Ignore warnings with suppressWarnings() .


2 Answers

Have you tried the following? (FROM: https://bookdown.org/yihui/bookdown/html-widgets.html)

install.packages("webshot")
webshot::install_phantomjs()

It worked for me. See also: https://github.com/rstudio/bookdown/issues/440

like image 119
Gorka Avatar answered Oct 07 '22 18:10

Gorka


I ran into this problem when using Bookdown, and the accepted solution did not work in my context. I resolved it after figuring out what the "YAML front-matter of your RMarkdown file" is. With bookdown, there is a .travis.yml file and a _bookdown.yml file, but you want to leave these two alone and these are not what the error message is referencing.

The "front-matter" would be the top of your RMarkdown file (if using bookdown it would be the "index.Rmd" file), see screenshot below: enter image description here

So just add always_allow_html: yes to the YAML header as its own line and it should work as expected (or give you a different error)

like image 29
Ricky Avatar answered Oct 07 '22 17:10

Ricky