R Markdown knit to pdf file not found - r

I tried to knit to pdf when an errormessage that said I had to update tinytex appeared, which i did. Then the message below showed up. I have tried uninstalling and reinstalling tinytex several times. I even tried installing and using miketex, that wouldn't work either. Can someone help me out please. I am very desperate my deadline is in a few hours.
processing file: Uebung-9.Rmd
|....... | 10%
ordinary text without R code
|.............. | 20%
label: 4)a)
|..................... | 30%
label: 4)b
|............................ | 40%
label: 4)b)
|................................... | 50%
label: 4)c)
|.......................................... | 60%
label: 4)d)
|................................................. | 70%
label: 4)d 20
|........................................................ | 80%
ordinary text without R code
|............................................................... | 90%
label: 4)d
|......................................................................| 100%
ordinary text without R code
output file: Uebung-9.knit.md
"C:/Program Files/RStudio/bin/quarto/bin/pandoc" +RTS -K512m -RTS Uebung-9.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output Uebung-9.tex --lua-filter "C:\Users\Karthika\Documents\R\win-library\4.1\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\Karthika\Documents\R\win-library\4.1\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable "geometry:margin=1in"
! LaTeX Error: File `Uebung-9_files/figure-latex/4' not found.
Error: LaTeX failed to compile Uebung-9.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Uebung-9.log for more info.
Execution halted

Related

Why Won't Rmarkdown Document Knit to PDF?

At a loss here. Trying to get R Studio to knit my Rmarkdown document to a PDF. I've installed as much as I can figure out. What am I missing?
processing file: MyFirstRMarkdown3.Rmd
|.......... | 14%
ordinary text without R code
|.................... | 29%
label: setup (with options)
List of 1
$ include: logi FALSE
|.............................. | 43%
ordinary text without R code
|........................................ | 57%
label: cars
|.................................................. | 71%
ordinary text without R code
|............................................................ | 86%
label: pressure (with options)
List of 1
$ echo: logi FALSE
|......................................................................| 100%
ordinary text without R code
output file: MyFirstRMarkdown3.knit.md
"C:/Program Files/RStudio/bin/quarto/bin/pandoc" +RTS -K512m -RTS MyFirstRMarkdown3.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output MyFirstRMarkdown3.tex --lua-filter "C:\Users\a12cof\AppData\Local\R\win-library\4.2\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\a12cof\AppData\Local\R\win-library\4.2\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable "geometry:margin=1in"
! Sorry, but C:\Users\a12cof\AppData\Local\Programs\MiKTeX\miktex\bin\x64\pdflatex.exe did not succeed.
! The log file hopefully contains the information to get MiKTeX going again:
! C:\Users\a12cof\AppData\Local\MiKTeX\miktex\log\pdflatex.log
Error: LaTeX failed to compile MyFirstRMarkdown3.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See MyFirstRMarkdown3.log for more info.
Execution halted

Unable to compile Rmd file with external tikz file

I'm trying to compile a pdf file from an Rmd document with some tikz graphics in it.
Example Rmd:
---
output:
pdf_document:
latex_engine: lualatex
header-includes:
- \usepackage{tikz}
---
# Introduction
Hello.
```{tikz img-plot, echo = FALSE, engine = "tikz", fig.ext = "pdf", fig.cap = "This is my image", code = readLines("testimg.tex")}
```
Figure \#ref(fig:img-plot) is not working.
referenced tikz file testimg.tex:
\begin{tikzpicture}
\node at (0.5, 0.5) {(a)};
\end{tikzpicture}
Compiling the Rmd file in Rusing
$ echo "rmarkdown::render('test.Rmd', output_file='test.pdf')" | R --no-save -q
gives me the following log:
rmarkdown::render('test.Rmd', output_file='test.pdf')
processing file: test.Rmd
|
|
| 0% |
|.......................
| 33% ordinary text without R code
|
|...............................................
| 67% label: img-plot (with options) List of 5 $ echo : logi
FALSE $ engine : chr "tikz" $ fig.ext: chr "pdf" $ fig.cap: chr
"This is my image" $ code : language readLines("testimg.tex")
|
|......................................................................|
100% ordinary text without R code
output file: test.knit.md
/usr/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from
markdown+autolink_bare_uris+tex_math_single_backslash --output
test.tex --template
/usr/lib/R/library/rmarkdown/rmd/latex/default-1.17.0.2.tex
--highlight-style tango --pdf-engine lualatex --variable graphics=yes --lua-filter /usr/lib/R/library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /usr/lib/R/library/rmarkdown/rmd/lua/latex-div.lua --variable 'geometry:margin=1in' --variable 'compact-title:yes' ! error: (file "test_files/figure-latex/""img-plot-1".pdf) (pdf
backend): canno
Error: Failed to compile test.tex. See
https://yihui.name/tinytex/r/#debugging for debugging tips. See
test.log for more info. Execution halted
The error log shows a double quote in ""img-plot-1".pdf. Could this have something to do with it?
I used to be able to compile a similar file a few weeks ago, which is why my guess is that some update in an R package, pandoc or somewhere else on my system broke it. Any ideas what the root of this might be?
System info:
OS: Linux Kernel 4.19.85-1-MANJARO
R 3.6.1
rmarkdown package: 1.17
pandoc 2.7.3

Latex shell-escape options in YAML header don't use

I'm writing a report on Rmarkdovn but when you try to compile - pandoc_args options ignored when compile pdf.
I find this question:
Is it possible to include svg image in pdf document rendered by rmarkdown?
But it does not work because --latex-engine-opt replaced by --pdf-engine-opt. I replaced, but also did not work.
Compilation command:
Rscript -e "rmarkdown::render('test.rmd')"
test.rmd
---
title: Test
papersize: a4paper
output:
pdf_document:
latex_engine: pdflatex
pandoc_args: [
--pdf-engine-opt, -shell-escape,
--pdf-engine-opt, -interaction=nonstopmode]
header-includes:
- \usepackage{minted}
---
Output:
processing file: test.rmd
|................................ | 50%
ordinary text without R code
|.................................................................| 100%
label: unnamed-chunk-1 (with options)
List of 1
$ engine: chr "python"
output file: test.knit.md
/usr/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template /home/renesat/R/x86_64-pc-linux-gnu-library/3.5/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --pdf-engine-opt --shell-escape --pdf-engine-opt -interaction=nonstopmode --variable 'geometry:margin=1in' --variable 'compact-title:yes'
! Package minted Error: You must invoke LaTeX with the -shell-escape flag.
Error: Failed to compile test.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See test.log for more info.
Execution halted
I can use knitr -> pandoc -> xelatex, but it would be more convenient to use YAML header.
R Markdown documents are compiled to PDF via tinytex::latexmk(). To enable the -shell-escape option for your LaTeX engine, you may set the global option tinytex.engine_args, e.g., add this code chunk to your document:
```{r, include=FALSE}
options(tinytex.engine_args = '-shell-escape')
```
See the help page ?tinytex::latexmk for more information.
The LaTeX engine is called by tinytex::latexmk() instead of Pandoc, so the Pandoc argument --pdf-engine-opt won't work.

r knit to pdf/html: pandoc document conversion failed with error 2

The R Markdown file seems to work in Rstudio. The r Markdown file can be converted into word, but not pdf/html.(Yesterday it gave different problem, so I change my question here.)
Any help will be appreciated!
This is the context of my Markdown file:
---
title: "Test"
author: "Test"
date: "2018/9/8"
output: html_document
---
## R test
```{r test}
x<-rnorm(500)
y<-rnorm(x*10)
ls()
plot(x,y)
rm(x,y)
```
This is an test.
This is the outcome is I knit to html:
|...................... | 33%
ordinary text without R code
processing file: test.Rmd
|........................................... | 67%
label: test
|.................................................................| 100%
ordinary text without R code
/usr/local/bin/pandoc +RTS -K512m -RTS test.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable 'theme:bootstrap' --include-in-header /var/folders/_h/013l11r91m3gny4lqwsvh5qh0000gn/T//Rtmpfvxqld/rmarkdown-str268664475eb.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
output file: test.knit.md
--smart/-S has been removed. Use +smart or -smart extension instead.
For example: pandoc -f markdown+smart -t markdown-smart.
Try pandoc --help for more information.
error: pandoc document conversion failed with error 2
stop processing
This is the outcome if I knit to pdf:
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: test
processing file: test.Rmd
|.................................................................| 100%
ordinary text without R code
/usr/local/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine /Library/TeX/texbin/pdflatex --variable graphics=yes --variable 'geometry:margin=1in'
output file: test.knit.md
--latex-engine has been removed. Use --pdf-engine instead.
Try pandoc --help for more information.
error: pandoc document conversion failed with error 2
stop processing
A little background might help:
Pandoc is a Haskell binary (i.e. a distinct piece of non-R software), that is shipped with RStudio for sake of running RMarkdown conversion. It seems you are getting some deprecation warnings, like:
--latex-engine has been removed. Use --pdf-engine instead.
--smart/-S has been removed. Use +smart or -smart extension instead.
This tells me you probably have an older version of RStudio, thus an older version of Pandoc. You may want to reinstall RStudio to make sure you have the appropriate Pandoc version, then debug from there.
Also, make sure to reinstall knitr and rmarkdown with the newest versions.

Specifying multiple simultaneous output formats in knitr (new)

Can I write a YAML header to produce multiple output formats for an R Markdown file using knitr? I could not reproduce the functionality described in the answer for the original question with this title.
This markdown file:
---
title: "Multiple output formats"
output:
pdf_document: default
html_document:
keep_md: yes
---
# This document should be rendered as an html file and as a pdf file
produces a pdf file but no HTML file.
And this file:
---
title: "Multiple output formats"
output:
html_document:
keep_md: yes
pdf_document: default
---
# This document should be rendered as an html file and as a pdf file
produces an HTML file (and an md file) but no pdf file.
This latter example was the solution given to the original question. I have tried knitting with Shift-Ctrl-K and with the Knit button in RStudio, as well as calling rmarkdown::render, but only a single output format is created, regardless of the method I use to generate the output file.
Possibly related, but I could not identify solutions:
How do I produce R package vignettes in multiple formats?
Render all vignette formats #1051
knitr::pandoc can't create pdf and tex files with a single config #769
Multiple formats for pandoc #547
An allusion to multiple output format support in a three year old RStudio blog post
Using R version 3.3.1 (2016-06-21), knitr 1.14, Rmarkdown 1.3
I actually briefly mentioned in Render all vignette formats #1051 and you missed it:
rmarkdown::render('your.Rmd', output_format = 'all')
It is documented on the help page ?rmarkdown::render.
Notwithstanding Yihui Xie's authoritative answer, and with due respect to the author of a great package, there are many cases in which output_format = 'all' is sub-optimal.
One of the issues that this solution raises is that the R script is re-processed from scratch for each format. Proof:
rmarkdown::render("new.Rmd", output_format = c("html_document", "pdf_document"))
processing file: new.spin.Rmd
|....................... | 33%
ordinary text without R code
|............................................... | 67%
label: unnamed-chunk-1
|......................................................................| 100%
ordinary text without R code
output file: new.knit.md
"C:/Users/fabrn/AppData/Local/Pandoc/pandoc" +RTS -K512m -RTS new.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output new.html --lua-filter "C:\Users\fabrn\R\win-library\4.0\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\fabrn\R\win-library\4.0\rmarkdown\rmarkdown\lua\latex-div.lua" --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\fabrn\R\win-library\4.0\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" --include-in-header "C:\Users\fabrn\AppData\Local\Temp\RtmpW6Vban\rmarkdown-str3490247b1f1e.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
Output created: new.html
processing file: new.spin.Rmd
|....................... | 33%
ordinary text without R code
|............................................... | 67%
label: unnamed-chunk-1
|......................................................................| 100%
ordinary text without R code
output file: new.knit.md
"C:/Users/fabrn/AppData/Local/Pandoc/pandoc" +RTS -K512m -RTS new.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output new.tex --lua-filter "C:\Users\fabrn\R\win-library\4.0\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\fabrn\R\win-library\4.0\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable "geometry:margin=1in"
This really is an issue when it comes to processing big data.
In real-world examples, I usually use latex output as a single rmarkdown::render output, then reprocess the .tex files using pandoc or similar tools (like prince for pdf). So my workflow is like:
rmarkdown::render('new.R', output_format = 'latex_document')
lapply(c("html", "pdf", ...),
function(form) rmarkdown::pandoc_convert("new.tex", output=paste0("new.", form)))
The bottom line is: all depends on your data. If small, output_format='all' is straightforward.
If big, you are better off with a common-ground format (latex is a good choice but html may be better in some cases) as an input to conversion tools.

Resources