Why can't I knitting the R markdown to PDF? - r

When I try to knit to PDF I have this error:
! Package inputenc Error: Unicode char \u8:。 not set up for use with LaTeX.
See the inputenc package documentation for explanation.
Type H for immediate help.
...
l.387 explained by ``gdp''。
Try running pandoc with --latex-engine=xelatex.
pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
Execution halted
I did includes all files in the working directory but still don't know why.

I could not comment on the previous post by scoa, but the YAML header argument misses a space and should read:
output:
pdf_document:
latex_engine: xelatex

I had a similar problem once. Try installing Pandoc on your machine, reboot and try again. You can download Pandoc here.
Also, you'd most likely need to install MiKTeX.
I hope this helps.

This is an encoding error. The easiest way to deal with it is to add the following line in the YAML preamble of your document.
---
output:
pdf_document:
latex_engine:xelatex
---

Related

Trouble with using Latex with R markdown

Hey I'm trying to use some latex in an R markdown file but I'm getting this error:
Try other LaTeX engines instead (e.g., xelatex) if you are using pdflatex. For R Markdown users, see https://bookdown.org/yihui/rmarkdown/pdf-document.html
Error: Failed to compile M5_collab.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See M5_collab.log for more info.
In addition: There were 33 warnings (use warnings() to see them)
Execution halted
I've checked out the bookdown website and I've installed tinytex
install.packages("tinytex")
Can someone let me know what's going wrong? How can I solve this?
Thank you
I had the same problem as you.
In my case I wanted to generate a pdf file and received this message you received.
I solved the problem of defining latex_engine as follows:
---
title: "Report"
output:
pdf_document:
latex_engine: xelatex
---

'Error in gregexpr' when render R Markdown to HTML

My RStudio(version 1.1.414) is not able to render a R Markdown file into HTML. I have a very simple R Markdown file called testHTML.Rmd:
---
title: "Untitled"
output:
html_document: default
---
## R Markdown
This is a test!
In my main R code, I am calling the render() statement as render('testHTML.Rmd'). I got the following error message related to regexp:
Error in gregexpr("(?)`r[ #]([^`]+)\\s*`", "---\ntitle:
\"Untitled\"\noutput:\n html_document: default\n \n---\n", : invalid
regular expression '(?<!(^| ))r[ #]([^]+)\s*`', reason 'Invalid
regexp'
Has anyone seen this error before when knit an R Markdown file? What is the solution?
For me updating all installed packages worked after I got the same error message.
The problem occured after updating RStudio to 1.1.463 and R to 3.5.2. I was asked to update knitr, rmarkdown and yaml ( I think, at least three packages were mentioned ). After updating yaml the error occured.
Updating all existing packages made the error disappear again. Hope this helps.

RMarkdown xelatex !Missing & Inserted

I originally posted with issues here:
Rmarkdown with xelatex
I have since reinstalled, but now I'm having an entirely new issue.
Using the following code (inside a .Rmd file):
---
header-includes:
- \usepackage{graphicx}
output:
pdf_document:
latex_engine: xelatex
---
```{r}
knitr::include_graphics("F:/Big Folder/My Folder/image.png")
```
I get the following error:
! Missing $ inserted.
<inserted text>
$
l.134 .../Big Folder/My Folder/image}
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
I think it has something to do with the space in the path, because when I put the image directly in F, it works fine.
Unfortunately, this project requires that I use folders with spaces in the name.
I'm on Windows 10 64 bit, running MikTex 2.9 with updated packages (including fontspec). Miktex is installed in program files, but I also tried an install to a different folder but had the same result.
I'm also running a recently installed/updated rstudio with updated knitr and rmarkdown packages.
This does work on pdflatex, even with spaces in the file name.
Got it, the actual image file was formatted as image_something.png.
The "_" was throwing it off and removing it fixed it.
Also, if I want to keep the underscore I need to add two escape characters "\\".
F:/Big Folder/image\\_something.png
This is somewhat different than the non rmarkdown latex solution in that it only requires a single escape character.
This solution was modified from https://tex.stackexchange.com/questions/266575/how-can-i-write-an-under-dash-in-text-without-invoking-italics-or-some-weird-fon.
I would still be curious as to why spaces are allowed on pdflatex but not xelatex.

R check warning: Files in the 'vignettes' directory but no files in 'inst/doc'

Lately I get a warning for my vignette on Win R Development Version when doing a cran check.
Files in the 'vignettes' directory but no files in 'inst/doc'
This warning only appears with the Win Dev version.
For Mac, AppVeyor and Travis no warning appears.
The problem is, I don't know what the warning wants to tell me.
As far as I know I do not have to put files in inst/doc.
Here is the complete warning message:
Files in the 'vignettes' directory but no files in 'inst/doc':
'Figures.d/Rlogo.png', 'Figures.d/distribution.pdf',
'Figures.d/distributionbar.pdf', 'Figures.d/gapsize.pdf',
'Figures.d/imputations.pdf', 'Figures.d/imputations2.pdf',
'Figures.d/sponsorlogo.jpg', 'Figures.d/statsna.png',
'Figures.d/tsairgap.png', 'Introduction.pdf', 'Introduction.tex',
'RJournal.sty'
In my case, I was getting this issue because I had specified my YAML as per #Claudia's answer, but I had specified rmarkdown as the VignetteBuilder in the DESCRIPTION file. Using VignetteBuilder: knitr in my DESCRIPTION file fixed the problem.
I had a similar issue with an Rmd vignette. I fixed it by changing the YAML header of the vignette to something like this:
---
author: "Name Surname"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Title of your vignette}
%\usepackage[UTF-8]{inputenc}
---
I fixed the problem with adding the .pdf output of my Vignette to inst/doc
Although I am not sure, if this is the supposed solution, it made the warning disappear.
I was getting the error on more than just the Win R Development version, but for me the fix was adding markdown and knitr in the Suggests field in the DESCRIPTION file. Then, I guess it was clear to the package compiler that the vignette was designated as a markdown/HTML doc.
These lines are in my markdown YAML header:
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Example for estimating the case fatality ratio}
%\VignetteEngine{knitr::knitr}
\usepackage[utf8]{inputenc}
During the compiling of your R package, those files are generated and cause your issue.
You should install the package gitignore, then in the main folder you have to create a text file named ".gitignore" (no extension) and add the address of the files you want to ignore. For example, vignettes/*.pdf

How to set up animation plot in pdf output of Knitr

I want to test whether the animation works in pdf output from .Rmd file (see the figure below).
I have installed the FFmpeg with brew install ffmpeg --with-libvpx on my Mac OS and sudo tlmgr install animate typed in terminal indicates that the animate package is already available for my Tex (tlmgr install: package already present: animate). However, the command listed below seems not work yet,although it works fine if I replace pdf_document with html_document. What might be the problem for this? I have pasted the error information in the final section (I have referred to a related question here: Plot animation in knitr rmarkdown).
---
title: "Example"
author: ""
header-includes:
- \usepackage{animate}
output:
pdf_document
---
```{r,fig.show='animate', out.width = ''}
for(i in 1:10) plot(rnorm(10))
```
---
output file: test.knit.md
! Missing number, treated as zero.
\relax
l.133 ...les/figure-latex/unnamed-chunk-1-}{1}{10}
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted
PDF doesn't support animations, except MOV apparently. The first couple of google results for 'PDF gif support' are informative, including this stackoverflow question: Is it possible to embed animated GIFs in PDFs?

Resources