Rmarkdown knit error: Fault/access violation in generated code - rstudio

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.

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/

Updating pandoc fixed this for me.
https://pandoc.org/installing.html
Thanks #EuGENE. Adding here as an answer for clarity.

Related

Multiple problems installing TeX Live 2021 on Windows 10

I have a Windows 10 laptop where no TeX distribution was ever installed before (double-checked for config directories, files, and environment variables).
Wanting to install TeX Live 2021, I followed the full installation guide and also read the Windows-specific warnings. I've now tried several times, following different installation procedures - cleaning up everything (deleting base & user directories, environment variables, etc) before each time - but still don't manage to get a working installation. Before I report a bug at tex-live#tug, I wanted to ask for advice here, in case I'm doing something wrong. Here is what I did, step by step, and the problems I encountered in the process.
1. First I tried running the recommended online installer install-tl-windows.exe. It never got past the screen that tries to contact or load from a repository, even after a 30-min wait. Tried a dozen times, choosing different mirrors nearby and far away. No luck.
2. Then I downloaded and unpacked the install-tl.zip and run install-tl-windows.bat therein. This time the main installation window appeared. I left all default paths and environment variables (note that I do have write access to C:); in the selection scheme I unselected all languages except US & UK English, unselected XeTeX, LuaTeX, ConTeXt; also unselected TeXworks (I use Emacs), and clicked Install. After one to three hours (depending on the mirror I chose), the installation was complete.
I tried compiling a minimal latex document (see below), and got an error similar to the one in this old question:
I can't find the format file `pdflatex.fmt'
Following the advice in the answers to that question and similar questions elsewhere online such as this, I tried running texhash and fmtutil-sys --all. The latter gave the error
no appropriate script or programme found fmtutil.
for which there are also many posts online.
2a. Not understanding what the problem could be, I re-tried with all possible combinations of the following three options: (a) choosing different mirrors; (b) leaving the full selection of packages (ie without unselecting some languages, LuaTeX etc); (c) redoing the procedure by choosing "Run as Administrator". No luck.
3. At this point I tried downloading the ISO file with the full installation. Mounted the image and run install-tl-windows.bat (as normal user, as recommended; I repeat that I do have write access to C:). Everything proceeded as in step 2. above. At the end of the installation I tried running pdflatex on the minimal latex document. New error this time:
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021/W32TeX) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./minimal-template.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-02-18>
! LaTeX Error: File `article.cls' not found.
Very strange. A file search revealed that article.cls is in the TeXLive file system; but kpathsea did not see it indeed.
4. At this point I opened the TeX Live Shell from the Start Menu; selected a CTAN mirror; updated the TL Manager which was not up to date; updated all packages; run Regenerate filename database; and run Regenerate formats. With the latter I got this error:
tex live shell:
mtutil [INFO]: total formats: 59
fmtutil [INFO]: exiting with status 53
C:\texlive\2021\bin\win32\runscript.tlu:915: command failed with exit code 53:
perl.exe c:\texlive\2021\texmf-dist\scripts\texlive\fmtutil.pl --sys --all
Here is a snip from the full set of errors appearing in the "Other" tab (I'm replacing my user directory with asterisks for privacy; note that I do have write access to these directories):
start load https://www.nic.funet.fi/pub/TeX/CTAN/systems/texlive/tlnet
finish load https://www.nic.funet.fi/pub/TeX/CTAN/systems/texlive/tlnet
start load http://contrib.texlive.info/current
finish load http://contrib.texlive.info/current
running mktexlsr ...
done running mktexlsr.
running mtxrun --generate ...
done running mtxrun --generate.
running updmap-sys ...
done running updmap-sys.
regenerating fmtutil.cnf in C:/texlive/2021/texmf-dist
running fmtutil-sys --byengine luatex --no-error-if-no-format --no-error-if-no-engine=luajithbtex,luajittex,mfluajit --status-file=C:\Users\***\AppData\Local\Temp\rPSb0Dpak2\WW_dJvUHgX ...
tlmgr.pl: fmtutil-sys --byengine luatex --no-error-if-no-format --no-error-if-no-engine=luajithbtex,luajittex,mfluajit --status-file=C:\Users\***\AppData\Local\Temp\rPSb0Dpak2\WW_dJvUHgX failed (status 255), output:
Unknown option: status-file
Try "fmtutil --help" for more information.
C:\texlive\2021\bin\win32\runscript.tlu:915: command failed with exit code 255:
perl.exe c:\texlive\2021\texmf-dist\scripts\texlive\fmtutil.pl --sys --byengine luatex --no-error-if-no-format --no-error-if-no-engine=luajithbtex,luajittex,mfluajit --status-file=C:\Users\***\AppData\Local\Temp\rPSb0Dpak2\WW_dJvUHgX
running fmtutil-sys --byengine luajithbtex --no-error-if-no-format --no-error-if-no-engine=luajithbtex,luajittex,mfluajit --status-file=C:\Users\***\AppData\Local\Temp\rPSb0Dpak2\WW_dJvUHgX ...
I tried to continue anyway with Regenerate fontmaps, and then tried again pdflatex on the minimal document. New error:
This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021/W32TeX) (preloaded format=pdflatex)
restricted \write18 enabled.
---! c:/texlive/2021/texmf-var/web2c/pdftex/pdflatex.fmt made by different executable version
(Fatal format file error; I'm stymied)
5. I tried again steps 3. and 4., but with "Run as Administrator". Same errors.
OK at this point I give up and really don't know what to do. Am I doing something wrong? For the moment I have to concur with this post: installation of TeX Live 2021 is an utter failure.
Here is the minimal latex file I used for testing (copy & paste):
\documentclass{article}
\begin{document}
test
\section{Section}
test
\end{document}
Found, that the download is not working because the system path to "cmd.exe" is not found. Therefore: open a cmd window and add the system path prior to starting the .bat file (set PATH=%PATH%;C:\Windows\system32)

Sphinx rst2pdf: Numbering figures

I have some documents on Sphinx 2.x. In addition to an HTML version (make html), I want to export it in a PDF version as well, preferably using rst2pdf:
My documents have some figure images. Here's a snippet in index.rst.
.. figure:: ./_images/img01.png
Caption for img01.
.. figure:: ./_images/img02.png
Caption for img02.
I want to add "Figure <#>" in the beginning of every caption. Does anyone have any thoughts? Please note
numfig doesn't work with rst2pdf.
Update (3/22/2020). Add the following lines in conf.py.
numfig = True
numfig_format = {
'figure': 'Figure %s.'
}
numfig_secnum_depth = 1
In the HTML output it works.
In the rst2PDF version, you don't see "Figure #".
The :counter: directive doesn't work with Sphinx; I get the following error:
.. figure:: ./_images/img01.png
Figure :counter:`figure`. Caption for img01.
$ sphinx-build -b pdf ./source/ ./build/
Running Sphinx v2.4.4
/home/sarah/sphinx_test/lib/python3.6/importlib/__init__.py:126: RemovedInSphinx30Warning: sphinx.environment.NoUri is deprecated.
Check CHANGES for Sphinx API modifications.
return _bootstrap._gcd_import(name[level:], package, level)
Initiated sphinxcontrib-images backend: `sphinxcontrib_images_lightbox2.lightbox2:LightBox2`
building [mo]: targets for 0 po files that are out of date
building [pdf]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index
Exception occurred:
File "/home/sarah/sphinx_test/lib/python3.6/site-packages/docutils/nodes.py", line 439, in copy
return self.__class__(reprunicode(self), rawsource=self.rawsource)
AttributeError: 'CounterNode' object has no attribute 'rawsource'
The full traceback has been saved in /tmp/sphinx-err-1bzghsm6.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!

Attempting to display LaTeX in Anki causes error?

I'm trying to enable LaTeX for Anki flashcards. I have MikTex installed and, upon attempting to view cards with LaTex formatting, I get the following error:
Définissez Problème à l’exécution de latex.
Fichier généré : C:\Users\user\AppData\Local\Temp\anki_temp\tmp.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6800 64-bit)
entering extended mode
(tmp.tex
LaTeX2e <2018-04-01> patch level 5
("C:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\size12.clo"))
("C:\Program Files\MiKTeX 2.9\tex\latex\base\fontenc.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\base\t1enc.def"))
("C:\Program Files\MiKTeX 2.9\tex\latex\base\inputenc.sty"
! LaTeX Error: File `utf8x.def' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
No pages of output.
I've already disabled automatic package installation/prompting of the user to install unknown packages in MikTex, to no avail.
What can I do to fix this so that Anki displays LaTeX cards?
I was experiencing similar problems and none of the in-depth ansers seemed to help me , but I just stumbled upon a solution that works for me.
As long as I only use \( to begin LaTeX Code and \) to end it, everything works well on my two Windows computers, as well as my Android device.
example:
\(\sum_{k = 1}^{\infty}\frac{1}{k}\)
instead of
\begin{math}\sum_{k = 1}^{\infty}\frac{1}{k}\end{math}
Hope this helps other noobs as well.
Fixed the problem by following the tutorial at
http://www.eighthourlunch.com/content/anki-setting-latex-windows-7
One issue which was unclear in the tutorial was installation of the xml/sgml typesetting package. It is called passivetex and can be viewed at https://miktex.org/packages/passivetex
Use the filter menu in the packages tab of the miktex console to explicitly search for passivetex . Once installed, I updated the file name database (Tasks -> Update filename database) and Anki started working correctly.

Cannot use rmarkdown from RGui

I would like to generate a PDF via RMarkdown from the RGui.
I am able to knit the file via RStudio but it fails every time via RGui.
This is "essai.r" file that contains the render command.
library(rmarkdown)
library(knitr)
Sys.setenv(RSTUDIO_PANDOC="C:/Program Files (x86)/Pandoc")
rmarkdown::render("essai.Rmd", output_format = "pdf_document", clean = FALSE)
This is "essai.rmd"
---
title: "test"
output: pdf_document
---
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}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
And this is my configuration:
> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows Server 2012 R2 x64 (build 9600)
locale:
[1] LC_COLLATE=French_Switzerland.1252 LC_CTYPE=French_Switzerland.1252 LC_MONETARY=French_Switzerland.1252
[4] LC_NUMERIC=C LC_TIME=French_Switzerland.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.12.3 rmarkdown_0.9.5
loaded via a namespace (and not attached):
[1] magrittr_1.5 formatR_1.4 tools_3.3.0 htmltools_0.3.6 yaml_2.1.13 Rcpp_0.11.2
[7] stringi_1.0-1 stringr_1.0.0 digest_0.6.13 evaluate_0.8
And this is the error that appears every time:
> source("essai.r")
"C:/Program Files (x86)/Pandoc/pandoc" +RTS -K512m -RTS essai.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output essai.pdf --template "C:\PROGRA~1\R\R-33~1.0\library\RMARKD~1\rmd\latex\DEFAUL~2.TEX" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"
pandoc.exe: Cannot decode byte '\xbd': Data.Text.Internal.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream
Erreur : pandoc document conversion failed with error 1
I made sure that both files are saved as UTF-8. And also I tried to change my system locale.
What am I missing?
Regards

Error in publishing to RPubs from Rstudio

I installed the latest version of RStudio (RStudio 1.1.423 - Windows Vista / 7/8/10).
I'm trying to publish to RPubs, but in Global Options does not appear the option for Rpubs.
When I request Publish Document, the following error appears: Error occurred while executing method.
Rprofile:
I entered the command: options (rpubs.upload.method = "internal") at line 25 of Rprofile, but it did not resolve.
The solution is provided by a careful rereading of http://rstudio-pubs-static.s3.amazonaws.com/25030_8e9c9ffc3b3c423d9381d81543423502.html
"Put in options(rpubs.upload.method = “internal”) and no other text at all". Meaning that this line of code is the only code present in the .Rprofile file.
Previously I had been adding the line to a copy of the rest of the Rprofile text. The unnecessary code was the culprit.
I had the same error before. Turns out it was due to having an accent mark in a folder name from my directory (í). I just modified that one folder name and it worked fine.

Resources