Error when compile RMarkdown pdf file with package `vtable` - r-markdown

I encounter errors when running the following simple code in RMarkdown.
---
title: "debugging"
author: ""
date: "11/12/2021"
output: pdf_document
---
```{r}
library(vtable)
st(iris,out="kable")
```
I am using the latest version of tinytex and all R packages.
The error message looks like:
! Misplaced \noalign. \bottomrule ->\noalign
{\ifnum 0=`}\fi #aboverulesep =\aboverulesep \global... l.168 \bottomrule
Error: LaTeX failed to compile debug.tex. See
https://yihui.org/tinytex/r/#debugging for debugging tips. See
debug.log for more info. Execution halted
or
I was unable to find any missing LaTeX packages from the error log
manual.log. ! Misplaced \noalign. \addlinespace ->\noalign
{\ifnum 0=`}\fi #ifnextchar [{#addspace }{#addsp... l.190 \addlinespace
Error: LaTeX failed to compile manual.tex. See
https://yihui.org/tinytex/r/#debugging for debugging tips. See
manual.log for more info. In addition:
Warning messages:
1: package'vtable' was built under R version 3.6.2
2: package 'kableExtra' was built under R version 3.6.2 Execution halted
in my origin rmd file with similar code (different data frame).

Related

! LaTeX Error: Option clash for package fontspec

I am trying to generate pdf from rmarkdown file using xelatex as latex engine. The file generates pdf while using pdflatex as latex engine. But, if I use xelatex, the file is giving the following error.
`! LaTeX Error: Option clash for package fontspec.
Error: LaTeX failed to compile cvGeneration.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See cvGeneration.log for more info.
Execution halted`
When I checked the log file I got the following few lines only.
*`! LaTeX Error: Option clash for package fontspec.
See the LaTeX manual or LaTeX Companion for explanation.
Type H for immediate help.
...
l.65 ...Package[\eu#zf#math]{fontspec}[2008/08/09]
The package fontspec has already been loaded with options:
[]
There has now been an attempt to load it with options
[no-math]
Adding the global options:
,no-math
to your \documentclass declaration may fix this.
Try typing to proceed.`*
Can anyone tell me why this problem is generating particularly for xelatex? I am trying to implement xelatex, since it supports UTF-8 character.
Thanks In advance.
My YAML header is given below:
params:
cvName: RJ MIMI
name: "`r params$cvName`"
address:
www:
phone:
email:
linkedin:
headcolor: "00008B"
date: "`r format(Sys.time(), '%B')`"
output:
vitae::hyndman:
keep_tex: true
latex_engine: xelatex
header_includes:
- \ExecuteBibliographyOptions{useprefix=true}
- renewcommand{\bibfont}{\normalfont\fontsize{10}{12.4}\sffamily}
This is pretty far down the road, however, the easiest way to get past the fontspec error is to set defaultfontfeatures. (fontspec is the default in RMarkdown.)
I don't have all that is going into your code here, update your header_includes to:
header_includes:
- \ExecuteBibliographyOptions{useprefix=true}
- \defaultfontfeatures(Ligatures = TeX)
- renewcommand{\bibfont}{\normalfont\fontsize{10}{12.4}\sffamily}
This may still give you warnings because it's not right, but it works.

tinytex:::is_tinytex() returns true, but I still cannot knit to a PDF from rmarkdown

When I knit to pdf, I get a pop up that says "The code execution cannot proceed because luatex.dll was not found. Reinstalling the program may fix this problem." I click OK, then I get this output:
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX)
(preloaded format=pdflatex) restricted \write18 enabled. Running the
command
C:\Users\Ryan.M.Allen\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe
I can't find the format file `pdflatex.fmt'!
kpathsea: Running mktexfmt pdflatex.fmt
The command name is
C:\Users\Ryan.M.Allen\AppData\Roaming\TinyTeX\bin\win32\mktexfmt I was
unable to find any missing LaTeX packages from the error log
BA_LunchLearn.log. ! Running the command
C:\Users\Ryan.M.Allen\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe
! kpathsea: Running mktexfmt pdflatex.fmt
! The command name is
C:\Users\Ryan.M.Allen\AppData\Roaming\TinyTeX\bin\win32\mktexfmt
Error: LaTeX failed to compile BA_LunchLearn.tex. See
https://yihui.org/tinytex/r/#debugging for debugging tips. See
BA_LunchLearn.log for more info. In addition: Warning message: package
'corrplot' was built under R version 3.6.3 Execution halted
I have tried uninstalling tinytex and reinstalling it and then restarting Rstudio each time. I also get the output of TRUE when I run the command tinytex:::is_tinytex(). So I think it is on my machine but the pdf knit does not work.

RMarkdown can't find 'pdflatex.fmt' file

I am trying RMarkdown for the first time, using the very first example in Yihui's book "R Markdown A Definitive Guide":
---
title: "Hello R Markdown"
author: "Awesome Me"
date: "2018-02-14"
output: pdf_document
---
This is a paragraph in an R Markdown document.
Below is a code chunk:
options(tinytex.verbose = TRUE)
fit = lm(dist ~ speed, data = cars)
b = coef(fit)
plot(cars)
abline(fit)
The slope of the regression is `r b[1]
I installed TinyTex using the following as per Yihui's comments here:
devtools::install_github('yihui/tinytex')
tinytex:::install_prebuilt()
Running tinytex:::is_tinytex() yields TRUE.
Clicking Knit gives me the following output. There is an error line I can't find the format file 'pdflatex.fmt'
processing file: Testpdf1.Rmd
|....................... | 33%
ordinary text without R code
|............................................... | 67%
label: unnamed-chunk-1
|......................................................................| 100%
inline R code fragments
"C:/Users/xxxxxx/Documents/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS Testpdf1.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output Testpdf1.tex --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --lua-filter "C:/Users/xxxxxx/Documents/R/R-3.6.1/library/rmarkdown/rmd/lua/pagebreak.lua" --lua-filter "C:/Users/xxxxxx/Documents/R/R-3.6.1/library/rmarkdown/rmd/lua/latex-div.lua" --variable "geometry:margin=1in"
output file: Testpdf1.knit.md
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/W32TeX) (preloaded format=pdflatex)
restricted \write18 enabled.
I can't find the format file `pdflatex.fmt'!
kpathsea: Running mktexfmt pdflatex.fmt
The command name is C:\Users\xxxxxx\AppData\Roaming\TinyTeX\bin\win32\mktexfmt
I was unable to find any missing LaTeX packages from the error log Testpdf1.log.
! kpathsea: Running mktexfmt pdflatex.fmt
! The command name is C:\Users\xxxxxx\AppData\Roaming\TinyTeX\bin\win32\mktexfmt
Error: LaTeX failed to compile Testpdf1.tex. See https://yihui.org/tinytex/r/#debugging for debugging
tips. See Testpdf1.log for more info.
Execution halted
I am trying to compile a pdf file. I am running Windows behind my company firewall. Searching for that file 'pdflatex.fmt' on my computer yields nothing. I have been searching for solution on the net for a while but can't relate to the problem. Does anyone know how I go about solving this?
Update on 2020/05/14: this is unlikely to be the solution to the recent breakage in TeX Live. If anyone reached here through searches, you have to wait until the breakage is resolved.
It may be the same issue as this one, so please try
tinytex::tlmgr_install(c('texlive-scripts', 'dehyph-exptl'))

How to resolve rmarkdown to latex errors involving tikz devices

I am trying to compile an rmarkdown document that includes a geographic plot into a PDF file. Here is a MWE:
---
title: "Problems with maps in tikz"
output: pdf_document
---
```{r setup, include=FALSE}
library(ggplot2)
library(sf)
```
## sf:png
Builds find when `nctikz` chunk is excluded.
```{r nc}
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc) +
geom_sf(aes(fill = AREA))
```
## sf:tikz
This graphic fails to build.
```{r nctikz, dev = 'tikz'}
ggplot(nc) +
geom_sf(aes(fill = AREA))
```
I am compiling this document using the "Knit" button in RStudio. I'm going to discuss each of the errors / warnings I get when I compile the document in case one leads to the others.
tinytex
Every time I try to run a chunk that includes dev = 'tikz', tinytex will try to reinstall the pgf TeX package, then discover it's already there, then give up trying to link it. I'm able to build document with non-geographic tikz outputs, however, so I've mostly just accepted this fact.
tlmgr search --file --global '/tikzlibrarytopaths.code.tex'
Trying to automatically install missing LaTeX packages...
tlmgr install pgf
tlmgr: package repository http://mirror.utexas.edu/ctan/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr install: package already present: pgf
tlmgr path add
add_link_dir_dir: /usr/local/share/info/dir exists; not making symlink.
Invalid characters
Tikz (in knitr) seems unable to handle the degree symbol as part of a tex file. As a note, the nctikz-1.tex object can be built by pdflatex without issue.
! Package inputenc Error: Invalid UTF-8 byte "B0.
Quitting from lines 24-27 (test.Rmd)
Error: Failed to compile test_files/figure-latex/nctikz-1.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See nctikz-1.log for more info.
Underscore in filepath
I can get around the invalid characters error by suppressing the axis titles theme(axis.text = element_blank()) on my plot, but this then introduces another error dealing with bringing in a file.
! Missing $ inserted.
<inserted text>
$
l.3975 ...72.27pt,interpolate=true]{nctikz-1_ras1}
};
Quitting from lines 24-27 (test.Rmd)
The full line that generates this error is
\node[inner sep=0pt,outer sep=0pt,anchor=south west,rotate= 0.00] at (423.16, 120.24) {
\pgfimage[width= 14.45pt,height= 72.27pt,interpolate=true]{nctikz-1_ras1}};
The image it's trying to reference is barely an image (I think it's for the legend).
Environment
I am building this document on MacOS with a whole pile of libraries. In an effort to isolate the issue, I also attempted to build the document on Rstudio.cloud (Ubuntu) in a brand new project. In this environment, only the issue with the math environment / underscore occurs.
! Missing $ inserted.
<inserted text>
$
l.4049 ...72.27pt,interpolate=true]{nctikz-1_ras1}
};
Quitting from lines 26-28 (test.Rmd)
Error: Failed to compile test_files/figure-latex/nctikz-1.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See nctikz-1.log for more info.
Not a full answer, but I would like to document my current state:
It makes sense to enable debugging by adding
```{r, include=FALSE}
options(tinytex.verbose = TRUE)
```
to the Rmd file as suggested.
The pgf issue is sort of a red herring. With debugging we see that it happens after some other error occurs (illegal character or underscore in file path). The corresponding regular expression was recently introduced and should probably be extended to check for actual error messages from Tikz/pgf.
I can reproduce the illegal character on Debian Linux. Somehow ° is written as 0xB0, i.e. Latin-1 encoded instead of UTF-8. I am not sure why/where this is happening. BTW, I can process the resulting tex file directly with pdflatex only from RStudio, since that re-encodes the 0xB0 as a question mark. If I use pdflatex via Emacs or directly on the command line, I get the same error message.
Removing the degree symbol from the output via
```{r nctikz, dev = 'tikz'}
ggplot(nc) +
theme(axis.text = element_blank()) +
geom_sf(aes(fill = AREA))
```
I can reproduce the "underscore in file path" issue. With debugging turned on, one sees that the issue is again somewhere else:
Package pgf Warning: File "nctikz-1_ras1" not found when defining image "pgflas
timage". Tried all extensions in ".pdf:.jpg:.jpeg:.png:" on input line 3975.
! Missing $ inserted.
<inserted text>
$
l.3975 ...72.27pt,interpolate=true]{nctikz-1_ras1}
};
! ==> Fatal error occurred, no output PDF file produced!
The file nctikz-1_ras1.png that is present in the same directory as nctikz-1.tex is not found. One can reproduce this issue directly using
tinytex::latexmk("<path>/nctikz-1.tex", install_packages = FALSE, clean = FALSE)
However, if one changes to the directory first, no such error occurs:
setwd("<path>")
tinytex::latexmk("./nctikz-1.tex", install_packages = FALSE, clean = FALSE)

Pandoc document conversion failed with erro 127

I have a problem with RMarkDown-Scripts that are stored in the ~/ShinyApps folder of my Shiny server.
The RMarkDown file fails to build in RStudio as well as in the web browser. The error message is always the same:
Error: pandoc document conversion failed with error 127
In addition: Warning message:
In system(command) : system call failed: No child processes
Execution halted
Warning message:
system call failed: No child processes
The strange thing is that sometimes the build process works and the document will be displayed correctly. Usually, RStudio generates the HTML file before the pandoc error appears.
Here is a simple RMarkDown file that sometimes will lead to the pandoc document conversion failed error message:
---
title: "Test"
author: "Marco Nae"
date: "25 February 2016"
output: html_document
---
Text.
```{r}
print("R code")
```
Text
```{r, echo=FALSE}
plot(cars)
```
The system is CentOs.
Can anyone provide assistance?