How do you compile to pdf files in R? Problem

458 Views Asked by At

I have a similar problem as already described, but the answers do not help me, that is why I am writing one more post.

I try to compile a tex file (a standard example from the web) in R, but R cannot file the pdflatex file:

Error running C:/Users/vica/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code 1)

I tried

Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:/Users/vica/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex", sep=.Platform$path.sep))

or

Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\\Users\\vica\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\pdflatex", sep=.Platform$path.sep))

(if I am wrong with the syntax), but no effect.

I added a Renviron.site file in the respective directory, writing this in it:

PATH=C:\\Users\\vica\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\pdflatex;"${PATH}"

but no effect. When I write

Sys.getenv("PATH")

I get something strange:

 Sys.getenv("PATH")
[1] "C:\\Users\\vica\\Documents\\R\\R-4.0.3\\bin\\x64;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Users\\vica\\AppData\\Local\\Programs\\Python\\Python39\\Scripts\\;C:\\Users\\vica\\AppData\\Local\\Programs\\Python\\Python39\\;C:\\Users\\vica\\anaconda3;C:\\Users\\vica\\anaconda3\\Library\\mingw-w64\\bin;C:\\Users\\vica\\anaconda3\\Library\\usr\\bin;C:\\Users\\vica\\anaconda3\\Library\\bin;C:\\Users\\vica\\anaconda3\\Scripts;C:\\Users\\vica\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\vica\\AppData\\Local\\Programs\\Git\\cmd;C:\\Users\\vica\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\vica\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\;C:\\Users\\vica\\AppData\\Roaming\\TinyTeX\\bin\\win32;C:/Users/vica/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex"
> 

I tried to compile the sweave file (exa3.tex), this is what I got:

Writing to file exa3.tex Processing code chunks with options ... You can now run (pdf)latex on 'exa3.tex'

Running pdflatex.exe on exa3.tex...failed Error running C:/Users/vica/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code -1073740791 

But when I KNIT the Rnw file, I get the pdf. This is my exa3.Rnw:

---
title: "MyFile1"
author: "Victoria"
date: "6 5 2021"
output: pdf_document
---

## R Markdown
 Hello, World! 

This is my tex file:


\documentclass[a4paper]{article}
\SweaveOpts{concordance=TRUE}

\title{Sweave Example 1}
\author{Victoria Knopova}

\usepackage{Sweave}
\begin{document}

\maketitle

In this example we embed parts of the examples from the
\texttt{kruskal.test} help page into a \LaTeX{} document:

\end{document}

Maybe I do something entirely wrong when I compile *.tex files, but I do not understand what, I only learn R...

Can somebody help me? Thank you in advance. Victoria

**PS: I found another way: one can use this hint

Rmarkdown to LaTeX

in order to translate a *.Rmd file to *.tex **

0

There are 0 best solutions below