Pandoc error 1 when I knit

I am trying to knit an Rmarkdown together for a homework assignment, but I keep getting the following message:

"C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS PS2.knit.md --to docx --from markdown+autolink_bare_uris+tex_math_single_backslash --output PS2.docx --lua-filter "C:\Users\cms14\AppData\Local\R\win-library\4.2\rmarkdown\rmarkdown\lua\pagebreak.lua" --highlight-style tango
output file: PS2.knit.md

pandoc.exe: PS2.docx: openBinaryFile: permission denied (Permission denied)
Error: pandoc document conversion failed with error 1
Execution halted

I was able to knit this document earlier before adding Latex equations with the "$$" feature, but once I added them, the knit keeps giving me this error. Does anyone know how to fix this?

Update: In trying to knit to a PDF, I got the following error message.

Sorry, but C:\Users\cms14\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\cms14\AppData\Local\MiKTeX\miktex\log\pdflatex.log

Error: LaTeX failed to compile PS2.tex. See The R package tinytex - Helper Functions to Manage TinyTeX, and Compile LaTeX Documents - Yihui Xie | 谢益辉 for debugging tips. See PS2.log for more info.

Within this file, I see the message "GUI framework cannot be initialized." Does anyone know how to fix this?

Welcome to the forum.

I am not an expert in the area but I imagine that we need to see what the file looks like. Can you post a cut dovn version of the document and some sample data here?

These instructions are not really intended for Rmarkdown or Quarto but they may help a bit:

A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here.

Thanks for clarifying this. I am working with quarterly GDP data from FRED, and I am primarily working with the data using the arima() function in my markdown file. Here is part of my file

#Question d
Using this AR(3) model, we will determine if it implies the existence of business cycles.
Our model can be written as follows:

gdp_t = 3.19 + .3351gdp_{t-1} + .1514gdp_{t-2} - .1181gdp_{t-3} + \epsilon_t

Using the lag operators, we can develop the characteristic equation of the lag polynomial:

\phi(t) = (1 -.3351L - .1514L^2 + .1181L^3)

As for my data, here is what the dput() function gives me

dput(head(gdp, 10))
structure(c(-1.1, -0.8, 6.4, 6.2, 6.8, 2.3, 0.5, -5.4, -1.4,
4.2), class = c("xts", "zoo"), src = "FRED", updated = structure(1676668369.33708, class = c("POSIXct",
"POSIXt")), index = structure(c(-718070400, -710208000, -702259200,
-694310400, -686448000, -678585600, -670636800, -662688000, -654912000,
-647049600), tzone = "UTC", tclass = "Date"), dim = c(10L, 1L
), dimnames = list(NULL, "A191RL1Q225SBEA"))

I'm not sure if this is helpful, I can also attach the latex file error, too.

The MikTek error file contains this

2023-02-17 18:30:51,700-0500 INFO pdflatex - this process (24312) started by Rterm in directory C:\Users\cms14\OneDrive\Desktop\School\Time Series with command line: C:\Users\cms14\AppData\Local\Programs\MiKTeX\miktex\bin\x64\pdflatex.exe -halt-on-error -interaction=batchmode PS2.tex
2023-02-17 18:30:51,700-0500 INFO pdflatex - running on Windows 10.0.22621
2023-02-17 18:30:51,720-0500 INFO pdflatex - this is MiKTeX-PDFTEX 4.11.0 (1.40.24) (MiKTeX 22.10)
2023-02-17 18:30:51,765-0500 INFO pdflatex - allowing known shell commands
2023-02-17 18:30:51,912-0500 INFO pdflatex - going to create file: pdflatex.fmt
2023-02-17 18:30:51,912-0500 INFO pdflatex.core - start process: miktex formats build pdflatex --engine pdftex
2023-02-17 18:31:04,178-0500 FATAL pdflatex.core - GUI framework cannot be initialized.
2023-02-17 18:31:04,178-0500 FATAL pdflatex.core - Data:
2023-02-17 18:31:04,180-0500 FATAL pdflatex.core - Source: Libraries\MiKTeX\UI\Qt\mikuiqt.cpp:126
2023-02-17 18:31:04,180-0500 FATAL pdflatex - GUI framework cannot be initialized.
2023-02-17 18:31:04,180-0500 FATAL pdflatex - Info:
2023-02-17 18:31:04,180-0500 FATAL pdflatex - Source: Libraries\MiKTeX\UI\Qt\mikuiqt.cpp
2023-02-17 18:31:04,180-0500 FATAL pdflatex - Line: 126
2023-02-17 18:31:04,185-0500 INFO pdflatex - this process (24312) finishes with exit code 1
2023-02-17 18:31:04,200-0500 WARN pdflatex.core - still open: PS2.tex
2023-02-17 18:31:04,200-0500 WARN pdflatex.core - still open: PS2.log
2023-02-17 19:00:02,345-0500 INFO pdflatex - this process (8608) started by Rterm in directory C:\Users\cms14\OneDrive\Desktop\School\Time Series with command line: C:\Users\cms14\AppData\Local\Programs\MiKTeX\miktex\bin\x64\pdflatex.exe -halt-on-error -interaction=batchmode PS2.tex
2023-02-17 19:00:02,347-0500 INFO pdflatex - running on Windows 10.0.22621
2023-02-17 19:00:02,351-0500 INFO pdflatex - this is MiKTeX-PDFTEX 4.11.0 (1.40.24) (MiKTeX 22.10)
2023-02-17 19:00:02,357-0500 INFO pdflatex - allowing known shell commands
2023-02-17 19:00:02,811-0500 FATAL pdflatex.core - GUI framework cannot be initialized.
2023-02-17 19:00:02,811-0500 FATAL pdflatex.core - Data:
2023-02-17 19:00:02,811-0500 FATAL pdflatex.core - Source: Libraries\MiKTeX\UI\Qt\mikuiqt.cpp:126
2023-02-17 19:00:02,811-0500 FATAL pdflatex - GUI framework cannot be initialized.
2023-02-17 19:00:02,811-0500 FATAL pdflatex - Info:
2023-02-17 19:00:02,811-0500 FATAL pdflatex - Source: Libraries\MiKTeX\UI\Qt\mikuiqt.cpp
2023-02-17 19:00:02,811-0500 FATAL pdflatex - Line: 126
2023-02-17 19:00:02,811-0500 INFO pdflatex - this process (8608) finishes with exit code 1
2023-02-17 19:00:02,811-0500 WARN pdflatex.core - still open: PS2.tex
2023-02-17 19:00:02,811-0500 WARN pdflatex.core - still open: PS2.log

Thanks for the data.

As a cut-down example I was thinking of something that included code and YAMAL . See example below, but note it is a Quaro not Rmarkdown file.

A bit of googling suggests that this may be a MikTeX problem and suggests a missing LaTeX package. See R cmd check Latex error: FATAL pdflatex - GUI framework cannot be initialized

It is an old post but with a recent update, and it looks similar. If you are using TinyTex my understanding is that it should install missing packages on the fly but I don't use TinyTex so I may be wrong. When I started using Rmarkdown I already had a full TexLive installation.

My brute force suggestion if you are using TinyTex and you have enough space is to wipe TinyTex and do a complete MikTeX installation.

More sensible people may have less drastic solutions

---
title: "Exercise 2"
author: "Anon."
date: 2022-12-25
date-format: iso
number-sections: true
format: pdf
header-includes:
  - \usepackage{lipsum}
editor: visual

---

{r}
#| label: setup
#| include: false
library(tidyverse); library(kableExtra); library(lubridate); library(janitor);
library(readODS)

dat1  <- data.frame(xx = 1:5, yy = 5:1)


Introduction

Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}.

\lipsum[1]

{r}
#| echo: false
#| label: fig-silly.plot
#| fig-cap: Amazingly Useless Plot.
ggplot(dat1, aes(xx, yy)) + geom_line(aes(colour = "red"), show.legend = FALSE)


\lipsum[4]

\newpage

\lipsum[5]

This error can happen if the document is already opened - Rendering docx with rmarkdown* requires to have a document close so that it can be overwrite.

Did you check that ?

This is indeed a MikTeX issue as described by @jrkrideau

Yes this is right - auto installation does not work with MikTeX but does with a TexLive installation, including TinyTeX

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.