Rmarkdown, Rstudio: pandoc.exe: Error producing PDF from TeX source - r

I am trying to render a pdf document with the knit pdf button in RStudio, but I keep on getting this error:
! pdfTeX error (font expansion): auto expansion is only possible with scalable
fonts.
\AtBegShi#Output ...ipout \box \AtBeginShipoutBox
\fi \fi
l.167
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
I know there is a lot be found on the internet regarding error 43, but non of them helped me.
Does anyone know what it means exactly and where I can find the solution? It's peculiar because a few hours ago I had the same error but the rendering went well after adding this in my code:
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\", sep=.Platform$path.sep))
But now the error is back
EDIT
when trying a minimal example:
---
title: "test"
output: pdf_document
---
```{r results="asis"}
library(stargazer)
c1 <- c("test1","test1","test2","test2")
c2 <- c(1,2,3,4)
data_object <- as.data.frame(cbind(c1,c2))
names(data_object) <- c("test","test2")
stargazer(data_object,summary=FALSE,rownames=FALSE,type="html")
```
The error it gives is:
!pdfTeX error: pdflatex (file ec-lmr10): Font ec-lmr10 at 600 not found
==> Fatal error occurred, no output PDF file produced!
Trying to make PK font ec-lmr10 at 600 DPI...
Running miktex-makemf.exe...
miktex-makemf: The ec-lmr source file could not be found.
miktex-makepk: The application file ttf2pk.exe could not be found.
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
This is a different error, but still a 43 one. I checked it, but the font ec-lmr10 file is on the system. Somehow it can't be found.

The problem you have is a font related one. When you knit a PDF, knitr uses LaTeX and you have to know that "fonts" of LaTeX are not like the standard ones.
To solve your problem try to add the latin model font family by loading the package (at the very top):
\usepackage{lmodern}
For more detailed informations about how and where insert this piece of code in your document, have a look here.
This package allows you to have scalable fonts; not all fonts of all (font) packages are to so.
I think, but I might be wrong, because first versions of TeX and LaTeX were designed to work with METAFONT.
Edit
Your code works well for me, it does not produce any error. My idea is that happens because I have a complete Tex live distribution on my Mac (MacTeX). At this point I suppose that the problem relies on some packages that the r packages you use (like stargazer) use and you (we) do not know and won't (unless we analyze the code of course).
At this point my suggestion is to download a complete TeX distribution so you will be sure that any error related to PDF output is no related to the underlying tool that Studio uses to produce such PDFs (say, LaTeX).
You can find a complete LaTeX distribution for Mac and for Windows.

Related

R markdown beamer presentation returning undefined control sequence

Whenever I tried to knit R markdown in beamer presentation format, it keeps on giving me undefined control sequence.
It is fraustrating because it worked fine until yesterday and I have no idea what I changed that causes this error.
To show that my code is not the source of the problem, I simply tried to knit an empty page.
code:
---
title: "untitled"
output: beamer_presentation
---
Output:
output file: a.knit.md
! Undefined control sequence.
<argument> ...{subsubsection}\addtobeamertemplate
{theorem begin}{\expandaft...
l.322 }{}
My original file returns the exaclty same error message.
I tried:
reinstall LaTeX
reinstall RStudio
upgrade all packages in R
Any idea how to fix this?
This was just fixed by #UlrikeFischer. #JosephWright is preparing a new beamer release as we speak, it should be available as beamer v3.67 on ctan tomorrow.
As a temporary workaround, place these two files in the folder of your .rmd file:
https://raw.githubusercontent.com/josephwright/beamer/main/base/beamer.cls
https://raw.githubusercontent.com/josephwright/beamer/main/base/beamerbasesection.sty
(don't forget to delete these files again once you have the new beamer version, otherwise they might interfere with future updates)

RMarkdown: Not able to knit to pdf

I have been using Rmarkdown for some months but suddenly I can't knit to pdf any longer, I installed the latest version of rstudio and tinytex, Yet it's not building pdf. What else can I do?.
Below is the error message:
! Package inputenc Error: Unicode character ^^N (U+000E)
(inputenc) not set up for use with LaTeX.
Try other LaTeX engines instead (e.g., xelatex) if you are using pdflatex. See https://bookdown.org/yihui/rmarkdown-cookbook/latex-unicode.html
Error: LaTeX failed to compile Introduction-to-R-for-statistical-computing.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Introduction-to-R-for-statistical-computing.log for more info.
Execution halted
After I tried severally, I came across this tinytex::reinstall_tinytex() from Why "Knit to pdf" in RMarkdown throws error? today.
It works for me perfectly. The pdf was built with all my equations written in tex. Also document was knitted in word with all the statistical models. Thanks so much.

R markdown themes not knitting

Currently I'm working on automating a project. Problem: The program is failing to knit because of the following code:
output:
powerpoint_presentation:
reference_doc: ref.pptx
The error code states:
Could not find shape for Powerpoint content
Error: pandoc document conversion failed with error 63
Execution halted
When I put my presentation into Google Slides, the theme works without a problem. Any ideas on how to fix this?

knitr Minimal Demo not compiling correctly

Hi knitr experts: I cannot for the life of me figure out how to compile the knitr Miminal Demo .Rnw document correctly. When I download and run Yihui's Minimal Demo of knitr .Rnw file (link), the document compiles but incorrectly handles the R chunks:
I changed nothing, just opened and compiled. Help welcome. As an aside, would very much appreciate tips on whether this is how I should be going about adding R code into a latex template that UT-Austin requires for dissertation publication. Thanks.
I can reproduce your PDF file when using Sweave instead of knitr for translating the .Rnw file. When switching to knitr via the RStudio options (c.f. https://support.rstudio.com/hc/en-us/articles/200532247), I get an error message and no PDF, which probably reproduces #r2evans' results in the comments. I also get a warning message that line 19 is Sweave specific (\SweaveOpts{concordance=TRUE}). Removing that line, the file processes with knitr correctly producing

knitr -- ! LaTeX Error: File `figure/unnamed-chunk-1' not found

I'm new to knitr and to Latex.
I keep getting the error "! LaTeX Error: File `figure/unnamed-chunk-1' not found." The error message says:
>! LaTeX Error: File `figure/unnamed-chunk-1' not found.
> See the LaTeX manual or LaTeX Companion for explanation.
> Type H <return> for immediate help.
...
> l.77 ...[width=\textwidth]{figure/unnamed-chunk-1}
> I could not locate the file with any of these extensions:
> .png,.pdf,.jpg,.mps,.jpeg,.jbig2,.jb2,.PNG,.PDF,.JPG,.JPEG,.JBIG2,.JB2,.eps
I have a simple tex file
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage[font={small}]{caption}
\author{My Name }
\title{knitr example}
\begin{document}
\maketitle
<<loading,echo=F>>=
library(ggplot2)
#
<< message=F,fig.width=9,fig.height=6,out.width='\\textwidth',cache= TRUE>>=
mydata <- data.frame(year = seq(1901: 1950), debt = rnorm(50))
plot(mydata$year, mydata$debt, main = "Debt")
#
\end{document}
I cannot seem to locate anything that seems relevant. Clearly "figure/unnamed-chunk-1" should be showing up somewhere but I don't see anything in the knitr options document to suggest a specific way to save it and so far I don't understand enough about knitr to figure out a way to name a plot to be imported.
It has been solved in the knitr mailing list. The problem was due to use of absolute paths in the output argument in knit(), so figures and tex output were not in the same directory. It is not recommended to use absolute paths in general; see more discussion in the mailing list.
An old question, but it I stumbled the issues recently, whether on MacOS or Win. I have tried the solution above but didn't work. What works for me is to delete all the figure inside figure-latex folder and re-run the knit.

Resources