rmarkdown error: "myfile.tex"' had status 1 - r-markdown

I am trying to compile an RMarkdown document from an R script. This is the code I am running:
setwd("C:/Users/me/me_VN02_5676/myfolder")
rmarkdown::render("myrmd.Rmd",
output_file = "mypdf.pdf")
This results in the error:
Error: Failed to compile mypdf.tex.
In addition: Warning message:
running command '"pdflatex" -halt-on-error -interaction=batchmode "mypdf.tex"' had status 1
Does anyone know what is happening?
Additional Notes
The PDF file is created when I use the Knit button in RStudio
This code does produce the .Tex file and when I run that it produces the pdf but render() does not produce the pdf
When I run the .R file via the command line it works! The PDF is created but why doesn't it work in R studio?

It would help to provide a Minimal Working Example so that we can attempt to replicate the problem. However, there may be two potential causes:
File Paths Look Incorrect
In R, they should be specified with a single forward slash: https://stat.ethz.ch/R-manual/R-devel/library/base/html/file.path.html
setwd("C:/Users/me/me_VN02_5676/myfolder")
rmarkdown::render("myrmd.Rmd",
output_file = paste0("mypdf.pdf")
)
PDF Output File May be Open
Another potential cause of this is that the PDF file is open, and therefore pandoc cannot save the output PDF. Try closing the PDF and render the document again.
Link to previous issue in Knitr which relates to this: https://github.com/yihui/knitr/issues/1209

Related

Rmarkdown conversion to HTML

I am trying to knit a simple R-markdown document (default document I named "exampled.Rmd"). When I try to use the Knit button it shows the following error message:
Error: object 'y' not found
Execution halted.
It is interesting, because when I run the following from the r-console,
rmarkdown::render('example.Rmd')
it generates the HTML document in the folder.
Does anybody have any idea about what is going on?

I can't knit my rmarkdown files - pandoc error

My university provided laptop was recently replaced and now when I try to knit my Rmd files if get the following error:
pandoc.exe: \\: openBinaryFile: invalid argument (Invalid argument)
Error: pandoc document conversion failed with error 1
Execution halted
These files used to knit perfectly on my old laptop and all of the code blocks within the file still run without errors.
The pandoc_available() function returns TRUE
The answers to similar questions that I have searched suggest it is something to do with the file paths but I am not familiar enough with this to make sense of what I should do. I tried mapping a network drive (Z:) to the folder where the Rmd file is stored and then changing the working directory in RStudio to that drive but it hasn't helped (and now I don't know how to change it back to ~ or what that referred to in the first place)
I have also tried downloading the latest version of Pandoc and a search on Windows Explorer shows that has installed in my user directory but I also have a version in C:\Program Files\RStudio\bin. That has also not helped.
I'm not sure if this is relevant but here is the information on the R version that I am running:
R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
Can you tell me what other information is required to diagnose the problem and I will edit to include.
I am sorry this question is so poorly specified and would appreciate any help to improve it.
**** UPDATE ****
I have found that if I
(i) specify that I want a .md file in the YAML header,
(ii) create an .md file by knitting the markdown file,
(iii) copy that .md file manually to the Pandoc directory
(iv) run pandoc.exe -s -o test.knit.md test.html from the MSDOS command prompt within the Pandoc directory,
then I can create the html output file.
However, changing the working directory for RStudio to the Pandoc directory and running
x <- rmarkdown::render("test.Rmd", run_pandoc = FALSE, clean = FALSE)
knit_meta <- attr(x, "knit_meta")
rmarkdown::render( input = 'test.knit.md' , knit_meta = knit_meta )
as per https://stackoverflow.com/questions/38908766/how-to-generate-an-md-file-from-a-rmarkdown-file-containing-an-htmlwidget gives the same error as shown in my original post.
Does this prompt any thoughts that might lead to a solution to my problem?
The university IT people were able to solve my problem by uninstalling R and RStudio from the network drive and installing it on the C: drive and I am now able to knit successfully.

How to resolve rmarkdown to latex errors involving tikz devices

I am trying to compile an rmarkdown document that includes a geographic plot into a PDF file. Here is a MWE:
---
title: "Problems with maps in tikz"
output: pdf_document
---
```{r setup, include=FALSE}
library(ggplot2)
library(sf)
```
## sf:png
Builds find when `nctikz` chunk is excluded.
```{r nc}
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc) +
geom_sf(aes(fill = AREA))
```
## sf:tikz
This graphic fails to build.
```{r nctikz, dev = 'tikz'}
ggplot(nc) +
geom_sf(aes(fill = AREA))
```
I am compiling this document using the "Knit" button in RStudio. I'm going to discuss each of the errors / warnings I get when I compile the document in case one leads to the others.
tinytex
Every time I try to run a chunk that includes dev = 'tikz', tinytex will try to reinstall the pgf TeX package, then discover it's already there, then give up trying to link it. I'm able to build document with non-geographic tikz outputs, however, so I've mostly just accepted this fact.
tlmgr search --file --global '/tikzlibrarytopaths.code.tex'
Trying to automatically install missing LaTeX packages...
tlmgr install pgf
tlmgr: package repository http://mirror.utexas.edu/ctan/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr install: package already present: pgf
tlmgr path add
add_link_dir_dir: /usr/local/share/info/dir exists; not making symlink.
Invalid characters
Tikz (in knitr) seems unable to handle the degree symbol as part of a tex file. As a note, the nctikz-1.tex object can be built by pdflatex without issue.
! Package inputenc Error: Invalid UTF-8 byte "B0.
Quitting from lines 24-27 (test.Rmd)
Error: Failed to compile test_files/figure-latex/nctikz-1.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See nctikz-1.log for more info.
Underscore in filepath
I can get around the invalid characters error by suppressing the axis titles theme(axis.text = element_blank()) on my plot, but this then introduces another error dealing with bringing in a file.
! Missing $ inserted.
<inserted text>
$
l.3975 ...72.27pt,interpolate=true]{nctikz-1_ras1}
};
Quitting from lines 24-27 (test.Rmd)
The full line that generates this error is
\node[inner sep=0pt,outer sep=0pt,anchor=south west,rotate= 0.00] at (423.16, 120.24) {
\pgfimage[width= 14.45pt,height= 72.27pt,interpolate=true]{nctikz-1_ras1}};
The image it's trying to reference is barely an image (I think it's for the legend).
Environment
I am building this document on MacOS with a whole pile of libraries. In an effort to isolate the issue, I also attempted to build the document on Rstudio.cloud (Ubuntu) in a brand new project. In this environment, only the issue with the math environment / underscore occurs.
! Missing $ inserted.
<inserted text>
$
l.4049 ...72.27pt,interpolate=true]{nctikz-1_ras1}
};
Quitting from lines 26-28 (test.Rmd)
Error: Failed to compile test_files/figure-latex/nctikz-1.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See nctikz-1.log for more info.
Not a full answer, but I would like to document my current state:
It makes sense to enable debugging by adding
```{r, include=FALSE}
options(tinytex.verbose = TRUE)
```
to the Rmd file as suggested.
The pgf issue is sort of a red herring. With debugging we see that it happens after some other error occurs (illegal character or underscore in file path). The corresponding regular expression was recently introduced and should probably be extended to check for actual error messages from Tikz/pgf.
I can reproduce the illegal character on Debian Linux. Somehow ° is written as 0xB0, i.e. Latin-1 encoded instead of UTF-8. I am not sure why/where this is happening. BTW, I can process the resulting tex file directly with pdflatex only from RStudio, since that re-encodes the 0xB0 as a question mark. If I use pdflatex via Emacs or directly on the command line, I get the same error message.
Removing the degree symbol from the output via
```{r nctikz, dev = 'tikz'}
ggplot(nc) +
theme(axis.text = element_blank()) +
geom_sf(aes(fill = AREA))
```
I can reproduce the "underscore in file path" issue. With debugging turned on, one sees that the issue is again somewhere else:
Package pgf Warning: File "nctikz-1_ras1" not found when defining image "pgflas
timage". Tried all extensions in ".pdf:.jpg:.jpeg:.png:" on input line 3975.
! Missing $ inserted.
<inserted text>
$
l.3975 ...72.27pt,interpolate=true]{nctikz-1_ras1}
};
! ==> Fatal error occurred, no output PDF file produced!
The file nctikz-1_ras1.png that is present in the same directory as nctikz-1.tex is not found. One can reproduce this issue directly using
tinytex::latexmk("<path>/nctikz-1.tex", install_packages = FALSE, clean = FALSE)
However, if one changes to the directory first, no such error occurs:
setwd("<path>")
tinytex::latexmk("./nctikz-1.tex", install_packages = FALSE, clean = FALSE)

Inkscape export from PDF to EMF with the command line (output is blank)

I'm trying to convert a PDF file (of only one page) to EMF. If I do it from the Inkscape GUI with the default options the outcome is perfect.
But if I do it with command line the outcome is a blank page.
I'm using this command:
inkscape -f=test.pdf --export-emf=test.emf
Can anybody help?
Inkscape is working. I was trying to open the file with paint.exe

Some error about calling a .mexw64 file in Matlab code

Recently,I used Mex to compile some .cpp file into .mexw64.
The following is the specific process:
1)I put mexResize.cpp MxArray.cpp and MxArray.h into a folder;
2)Then I run a make.m and get a mexResize.mexw64 in the folder above:
Command window of matlab
3)Finally I use mexResize.mexw64 in my matlab code:
img1 = mexResize(img,[100,100]);
However,I met the error like the following:
Error information
There are some Chinese sentences above,I try to translate them as following:
"MEX The file appears unexpected standard exceptions"
"Error test (line 3)"
Apologize for my limited English.