3

I've got a particular bug in my environment such that I cannot consistently knit Rmarkdown files to HTML, Word documents, or PDFs. The ability to knit varies across by file type.

  • HTML - Sometimes it knits
  • Word document - Sometimes it knits
  • PDF - Never knits. Always throws the same error

The error is:

Segmentation fault/access violation in generated code
Error: pandoc document conversion failed with error 1

Up until a week ago, I was able to knit to all three file types in the same environment so this is a relatively recent bug. The high-level specs of my environment are:

  • OS: Windows 10
  • R: 3.4.3
  • RStudio: 1.1.419
  • knitr: 1.19
  • rmarkdown: 1.8
  • pandoc: 1.19.2.1
  • MiKTeX : 2.9

As an example of the inconsistency in the ability to knit, I crated a new .Rmd file in RStudio which creates the familiar standard template of summary(cars) and plot(pressure) etc. I didn't change anything about it. I was able to knit it successfully to HTML once, Word .docx once, and then I tried to knit to PDF and got the error above. I then went back and attempted to knit to both HTML and Word and received the error even though nothing changed from the original knit. This is just an example of the type of behavior. Different documents behave differently.

To troubleshoot, I've reinstalled R and RStudio (I believe pandoc comes up with the RStudio install so I've effectively reinstalled pandoc too). The reinstallation did not help. I've tried clearing the Knitr Cache. That didn't work either. I've browsed SO and the internet and found a few similar errors related to the Glasgow-Haskell compiler, but I have no idea what that is and if it's the source of the issue.

Here is an example of the .Rmd file that throws the error:

---
title: "Untitled"
author: "Vypa"
date: "February 8, 2018"
output:
  html_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

And here is the full console error:

Segmentation fault/access violation in generated code
Error: pandoc document conversion failed with error 1
In addition: Warning message:
running command '"C:/Users/Vypa/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS tst.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output tst.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\Vypa\Documents\R\R-3.4.3\library\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" --include-in-header "C:\Users\Vypa\AppData\Local\Temp\RtmpI9Gxsx\rmarkdown-str5db029544a23.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"' had status 1 
Execution halted

Any help or thoughts would be appreciated.

albert
  • 8,285
  • 3
  • 19
  • 32
Vypa
  • 71
  • 1
  • 6
  • 1
    `pandoc` is also up to date? – elcortegano Feb 08 '18 at 16:33
  • It would help if you'd write an example of .Rmd file – elcortegano Feb 08 '18 at 16:34
  • Hi EuGENE - I would think so, since `pandoc` is installed with RStudio and I have the latest stable version of RStudio. I'm having trouble finding the exact `pandoc` version in my RStudio install, however. – Vypa Feb 08 '18 at 16:38
  • Not sure about this, but `knitr::pandoc` is a function that, according to the `?pandoc` man page, calls the Pandoc software. My guess is that you need to install it. I'm not a Windows user, but I'm sure it's easy. See [here](https://pandoc.org/installing.html). – elcortegano Feb 08 '18 at 16:46
  • @Vypa execute `rmarkdown::pandoc_available() ` to show pandoc location and version – RLesur Feb 08 '18 at 16:55
  • 1
    @romles I think the function is `rmarkdown::pandoc_version()` to get the version. `pandoc_available()` simply returns a boolean for me. I've edited my post to show the version of pandoc, so thanks for pointing me in that direction. – Vypa Feb 08 '18 at 17:04
  • @tarleb I'm on Windows 10 as it says in the question. – Vypa Feb 08 '18 at 17:04
  • @Vypa I remind having this error when my output file is still opened (pdf in acrobat reader, for instance). Can you check with deleting all output files (docx, html, pdf, and intermediate .md files)? – RLesur Feb 08 '18 at 17:08
  • @Vypa can you also try with the development version of `rmarkdown`? – RLesur Feb 08 '18 at 17:13
  • @romles Good thought, but that doesn't do the trick. Even after wiping everything from the folder but the .Rmd file, I still get the same error. Not sure about a typo in the question. Did I spell `rmarkdown` wrong? – Vypa Feb 08 '18 at 17:17
  • @romles Great catch. Yes it was a typo. Thank you! It's version 1.8. I could try to install the dev. version but I am behind a firewall so `devtools::install_github` is always a risky proposition. Looking at the rmarkdown repo, I can't even find where a development version install is available. – Vypa Feb 08 '18 at 17:26
  • @Vypa it's easiest with `install_github`. You also can clone the repo and build from rstudio. Last option, download as zip, build and install (cumbersome) – RLesur Feb 08 '18 at 17:36
  • @Vypa Is your Rmd located in the same disk as pandoc? `C:` with your configuration – RLesur Feb 08 '18 at 17:46
  • @romles I installed the latest version of `rmarkdown` (1.8.10) from github and I still get the same error. The `C:` is the exact same as where `pandoc` is installed. – Vypa Feb 08 '18 at 17:57
  • @Vypa Have you seen [this issue](https://github.com/jgm/pandoc/issues/4021)? It was recently corrected but not released yet. – RLesur Feb 08 '18 at 18:02
  • @Vypa If your problem comes from this GHC bug, it's annoying. Options would be: compile pandoc from source (very cumbersome), use a docker image with rstudio (if docker is installed on your computer, it's very easy), downgrade your installation (knitr, rmarkdown and rstudio) – RLesur Feb 08 '18 at 18:35
  • 2
    @romles Thanks for all your help. I spoke too soon. After installing `rmarkdown` from github and then restarting R **and** RStudio, I am now able to knit all three document types. If you'd like to reply to this question, I'll mark your answer as correct. – Vypa Feb 08 '18 at 21:57
  • @Vypa thx for the proposition, but I have a little doubt that you won't get this bug again. – RLesur Feb 08 '18 at 22:03

2 Answers2

2

Encountered the same problem after a recent install of R & RStudio on Win10. Pandoc problem showed up on edit and knitr of previously err free .rmd file.

Resolved after installing latest preview ver of RStudio at

https://www.rstudio.com/products/rstudio/download/preview/

1

Updating pandoc fixed this for me.

https://pandoc.org/installing.html

Thanks @EuGENE. Adding here as an answer for clarity.