How do you compile to pdf files in R? Problem - r

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
**

Related

Bioconductor package "oligo" works fine on its own, but returns an error message when knitted as part of a .Rmd document

I am using Bioconductor package "oligo" to read in and analyze some .cel files and am running into trouble, specifically with reading in the files. However, this error only occurs when the code is part of an R Markdown document, but not when I run it from RStudio, so I know there is no issue with the actual files.
Here are the contents of the .Rmd file:
---
title: "Untitled"
output: html_document
---
```{r}
library(oligo)
celFiles <- list.celfiles("./cel_files/", full.names=TRUE)
raw.data <- read.celfiles(celFiles)
```
Knitting this file gives the following output:
Quitting from lines 12-15 (DE_Analysis.Rmd)
Error: checkChipTypes(filenames, verbose, "affymetrix", TRUE) is not TRUE
Execution halted
However, running the following code in Rstudio successfully reads in the files:
library(oligo)
celFiles <- list.celfiles("./cel_files/", full.names=TRUE)
raw.data <- read.celfiles(celFiles)
It seems that something about R Markdown does not agree with oligo -- any ideas as to what might be happening and how to fix the problem?

Any way of attaching .csl, .bib files by using `knitcitations` package?

I have tried to attach bibliography.bib, nature.csl files by using knitcitations packages on myPkg_vignette.Rmd, but when I execute the .Rmd file, I got following error:
pandoc-citeproc.exe: Could not find bibliography.bib
pandoc.exe: Error running filter pandoc-citeproc
Filter returned error status 1
Error: pandoc document conversion failed with error
I looked into knitcitations manual and how to attach .csl, .bib file by handy, but I got warning and can't attach these files on myPkg_vignette.Rmd.
Edit :
This is context of bibliography.bib:
#article{Vahid_Jalili_Musera_2015,
title = "MuSERA: Multiple Sample Enriched Region Assessment",
author = {Vahid Jalili, Matteo Matteucci, Marco Masseroli, Marco J. Morelli},
journal = "Briefings in Bioinformatics",
year = "2016",
pages = "1-15",
url = {http://bib.oxfordjournals.org/content/early/2016/03/23/bib.bbw029.abstract?keytype=ref&ijkey=8IlROGziM9XA7NS},
doi = "10.1093/bib/bbw029 ",
}
How can I attach bibliography.bib, nature.csl on package's vignette easily ? I read some post in SO and I confused about the given solution. I am quite new with using knitcitations packages, and I may get wrong with attaching .bib, .csl files in right way. Can any one help me out how to address this issues in Rstudio ? Any idea ? Thanks a lot :)
NEW EDIT :
I've read this post and followed the solution :
setwd('C:/Users/me/Documents/myPkg')
Sys.setenv(TEXINPUTS=getwd(),
BIBINPUTS=getwd(),
BSTINPUTS=getwd())
but bibliography.bib is not printed in .Rmd file. I changed the global option for weaving Rnw file to knitr. How can I print out bibliography on .Rmd file ? Any further help please ?
As with Dirk, it just works for me. Maybe you didn't put the YAML together properly, or maybe you never cited anything. Here's a sample document that works with your bib file:
---
title: "Biblio Example"
output: html_document
bibliography: bibliography.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Here's Some Text
This text cites the paper: [#Vahid_Jalili_Musera_2015].
## References
The bibliography will appear by magic at the end of the document, just
below this text.
See http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html for more details.
For me the problem was that my .bib file was listed in .Rbuildignore. Removing the entry solved the problem.
According to the r-pkg-dev mailing list answer from Duncan Murdoch, .Rbuildignore is "case-insensitively against the file and directory names relative to the top-level package source directory".
Therefore the entry xxx.bib ignored all .bib files recursively in my package directory and the error was thrown.

Cannot include figures via R/Sweave/LaTeX

I am trying to create a pdf vs R/Sweave/LaTeX that will include a plot. Here is the relevant snippet from my .Rnw file:
\begin{figure}
\begin{center}
<<fig=TRUE,echo=FALSE>>=
makeMyPlot()
#
\end{center}
\label{fig:one}
\end{figure}
When I run Sweave it generates a .pdf file named "analysis report-005.pdf" and a .tex file including the following line:
\includegraphics{analysis report-005.pdf}
So far, so good. But when I run
tools::texi2pdf('analysis report.tex')
I get this error
Error: running 'texi2dvi' on 'analysis report.tex' failed
LaTeX errors:
:218: LaTeX Error: File `analysis report-005' not found.
It looks like texi2pdf is failing to find the file because the extension, ".pdf", is not stated in the .tex file output. When I add ".pdf" directly to the relevant line of the .tex file, the error goes away. However, I shouldn't need to do this manually. I'm not sure if this is a problem with Sweave or texi2pdf; I suspect the latter. How can I fix it?

Using knit2pdf with Rmd files

Is it possible to use the knitr function knit2pdf() directly with R Markdown (Rmd) files? I've seen various tutorials/class notes that seem to suggest it can e.g. here and here (Ctrl+F "knit2pdf" in either).
But when I take a simple rmd file (saved as "test.rmd")
---
title: "knit2pdf test"
author: "A Aaronson"
date: "Thursday, February 19, 2015"
output: pdf_document
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
and try
library(knitr)
knit2pdf("test.Rmd")
I get the following error
results in:
output file: test.md
Error: running 'texi2dvi' on 'test.md' failed
LaTeX errors:
! Emergency stop
*** (job aborted, no legal \end found)
! ==> Fatal error occurred, no output PDF file produced!
! ==> Fatal error occurred, no output PDF file produced!
In addition: Warning message:
running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "test.md" --max-iterations=20 -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/bibtex/bst"' had status 1
Clicking the "Knit PDF" button always successfully generates a pdf. So am I missing an intermediate step?
I should add that knit2pdf() with Rnw files is working as expected for me, though I do still get the warning
running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "rnwtest.tex" --max-iterations=20 -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/bibtex/bst"' had status 1
Help greatly appreciated.
Your input file is in rmarkdown format.
You should use the render() function in the rmarkdown package to compile your document.
Try:
library("rmarkdown")
render("temp.rmd")

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