19

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?

wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90
  • 1
    How does your markdown file looks like? Do you have any function which produces html or java script output e.g. tables or plots? – Alex Mar 01 '17 at 22:24
  • 1
    I have plots yes. I can't reproduce because when I do a simple rmd, it works, it only doesn't work on the totality of it. I am wondering what this error even means exactly – wolfsatthedoor Mar 01 '17 at 22:37
  • It says that some function produces html output which is not suitable for a latex document. But I guess you can read that yourself. You could try to compile it to an html document and see if that works. – Alex Mar 01 '17 at 22:41
  • Ok thank you, I think it is from using plotly, instead of ggplot2 – wolfsatthedoor Mar 01 '17 at 22:43
  • 2
    @robertevansanders "I can't reproduce because when I do a simple rmd, it works, it only doesn't work on the totality of it": I think you can reproduce: just remove chunks and try to compile until the error disappears ; the last removed chunk is the one with the problem. You can then post a MCVE with just this code. – scoa Mar 02 '17 at 10:27
  • I used to have trouble with this, when using plotly graphs in my output. After changing back to ggplot for the pdf (and keeping the plotly ones for html) everything worked fine. – Rivka Feb 06 '19 at 00:00

4 Answers4

27

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)

Ricky
  • 1,005
  • 1
  • 12
  • 15
23

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

Gorka
  • 3,555
  • 1
  • 31
  • 37
  • 1
    Thanks, this saved me significant time in producing an R Markdown document that can create an html with interactive plotly and a Word document without any extra work! – the_SJC Oct 05 '20 at 19:05
0

You need to choose what format you want to KNIT to, tried to look at mine.

---
title: "<img src='www/binary-logo.jpg' width='240'>"
subtitle: "[<span style='color:blue'>binary.com</span>](https://github.com/englianhu/binary.com-interview-question) Interview Question I"
author: "[<span style='color:blue'>®γσ, Lian Hu</span>](https://englianhu.github.io/) <img src='www/ENG.jpg' width='24'> <img src='www/RYO.jpg' width='24'>白戸則道®"
date: "`r Sys.Date()`"
output:
  tufte::tufte_html:
    toc: yes
  tufte::tufte_handout:
    citation_package: natbib
    latex_engine: xelatex
  tufte::tufte_book:
    citation_package: natbib
    latex_engine: xelatex
link-citations: yes
---

KNIT

0

In my case, using quarto, I got this error if I had a .Rprofile file in my working directory. This file justs consists of some "library(knitr), library(kableExtra)" entries. However, removing this file makes it run again without error.

Produnis
  • 523
  • 1
  • 5
  • 14