I am trying RMarkdown for the first time, using the very first example in Yihui's book "R Markdown A Definitive Guide":
---
title: "Hello R Markdown"
author: "Awesome Me"
date: "2018-02-14"
output: pdf_document
---
This is a paragraph in an R Markdown document.
Below is a code chunk:
options(tinytex.verbose = TRUE)
fit = lm(dist ~ speed, data = cars)
b = coef(fit)
plot(cars)
abline(fit)
The slope of the regression is `r b[1]
I installed TinyTex using the following as per Yihui's comments here:
devtools::install_github('yihui/tinytex')
tinytex:::install_prebuilt()
Running tinytex:::is_tinytex() yields TRUE.
Clicking Knit gives me the following output. There is an error line I can't find the format file 'pdflatex.fmt'
processing file: Testpdf1.Rmd
|....................... | 33%
ordinary text without R code
|............................................... | 67%
label: unnamed-chunk-1
|......................................................................| 100%
inline R code fragments
"C:/Users/xxxxxx/Documents/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS Testpdf1.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output Testpdf1.tex --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --lua-filter "C:/Users/xxxxxx/Documents/R/R-3.6.1/library/rmarkdown/rmd/lua/pagebreak.lua" --lua-filter "C:/Users/xxxxxx/Documents/R/R-3.6.1/library/rmarkdown/rmd/lua/latex-div.lua" --variable "geometry:margin=1in"
output file: Testpdf1.knit.md
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/W32TeX) (preloaded format=pdflatex)
restricted \write18 enabled.
I can't find the format file `pdflatex.fmt'!
kpathsea: Running mktexfmt pdflatex.fmt
The command name is C:\Users\xxxxxx\AppData\Roaming\TinyTeX\bin\win32\mktexfmt
I was unable to find any missing LaTeX packages from the error log Testpdf1.log.
! kpathsea: Running mktexfmt pdflatex.fmt
! The command name is C:\Users\xxxxxx\AppData\Roaming\TinyTeX\bin\win32\mktexfmt
Error: LaTeX failed to compile Testpdf1.tex. See https://yihui.org/tinytex/r/#debugging for debugging
tips. See Testpdf1.log for more info.
Execution halted
I am trying to compile a pdf file. I am running Windows behind my company firewall. Searching for that file 'pdflatex.fmt' on my computer yields nothing. I have been searching for solution on the net for a while but can't relate to the problem. Does anyone know how I go about solving this?
Update on 2020/05/14: this is unlikely to be the solution to the recent breakage in TeX Live. If anyone reached here through searches, you have to wait until the breakage is resolved.
It may be the same issue as this one, so please try
tinytex::tlmgr_install(c('texlive-scripts', 'dehyph-exptl'))
Related
I encounter errors when running the following simple code in RMarkdown.
---
title: "debugging"
author: ""
date: "11/12/2021"
output: pdf_document
---
```{r}
library(vtable)
st(iris,out="kable")
```
I am using the latest version of tinytex and all R packages.
The error message looks like:
! Misplaced \noalign. \bottomrule ->\noalign
{\ifnum 0=`}\fi #aboverulesep =\aboverulesep \global... l.168 \bottomrule
Error: LaTeX failed to compile debug.tex. See
https://yihui.org/tinytex/r/#debugging for debugging tips. See
debug.log for more info. Execution halted
or
I was unable to find any missing LaTeX packages from the error log
manual.log. ! Misplaced \noalign. \addlinespace ->\noalign
{\ifnum 0=`}\fi #ifnextchar [{#addspace }{#addsp... l.190 \addlinespace
Error: LaTeX failed to compile manual.tex. See
https://yihui.org/tinytex/r/#debugging for debugging tips. See
manual.log for more info. In addition:
Warning messages:
1: package'vtable' was built under R version 3.6.2
2: package 'kableExtra' was built under R version 3.6.2 Execution halted
in my origin rmd file with similar code (different data frame).
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.
I am trying to generate pdf from rmarkdown file using xelatex as latex engine. The file generates pdf while using pdflatex as latex engine. But, if I use xelatex, the file is giving the following error.
`! LaTeX Error: Option clash for package fontspec.
Error: LaTeX failed to compile cvGeneration.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See cvGeneration.log for more info.
Execution halted`
When I checked the log file I got the following few lines only.
*`! LaTeX Error: Option clash for package fontspec.
See the LaTeX manual or LaTeX Companion for explanation.
Type H for immediate help.
...
l.65 ...Package[\eu#zf#math]{fontspec}[2008/08/09]
The package fontspec has already been loaded with options:
[]
There has now been an attempt to load it with options
[no-math]
Adding the global options:
,no-math
to your \documentclass declaration may fix this.
Try typing to proceed.`*
Can anyone tell me why this problem is generating particularly for xelatex? I am trying to implement xelatex, since it supports UTF-8 character.
Thanks In advance.
My YAML header is given below:
params:
cvName: RJ MIMI
name: "`r params$cvName`"
address:
www:
phone:
email:
linkedin:
headcolor: "00008B"
date: "`r format(Sys.time(), '%B')`"
output:
vitae::hyndman:
keep_tex: true
latex_engine: xelatex
header_includes:
- \ExecuteBibliographyOptions{useprefix=true}
- renewcommand{\bibfont}{\normalfont\fontsize{10}{12.4}\sffamily}
This is pretty far down the road, however, the easiest way to get past the fontspec error is to set defaultfontfeatures. (fontspec is the default in RMarkdown.)
I don't have all that is going into your code here, update your header_includes to:
header_includes:
- \ExecuteBibliographyOptions{useprefix=true}
- \defaultfontfeatures(Ligatures = TeX)
- renewcommand{\bibfont}{\normalfont\fontsize{10}{12.4}\sffamily}
This may still give you warnings because it's not right, but it works.
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)
I tried to run this sample code from opencv but I'm confused as to how to run it. It only shows this help message:
Usage: surf_matcher[options]
Available options:
Usage: surf_matcher_2.exe [params]
--cpu_mode, -m (value:false)
run without OpenCL
-h, --help (value:false)
print help message
-l, --1eft (value: box.png)
specify left image
-o, --output (value: SURF output . jpg)
specify output save path
-r, --right (value: box in scene.png)
specify right image
From my basic understanding of arguments, I tried many kinds of input arguments as follows:
-l box.png -r box_in_scene.png
--left box.png --right box_in_scene.png
--l box.png --r box_in_scene.png
But it still did not work. It did have this error but built successfully:
Severity Code Description Project File Line Suppression State
Error (active) the default constructor of "SURFMatcher<cv::BFMatcher>" cannot be referenced -- it is a deleted function surf_matcher_2 c:\Users\user\Documents\Visual Studio 2015\Projects\surf_matcher_2\surf_matcher_2\surf_matcher_2.cpp 195
I got it to run a long time ago but replicating the old project didn't work either.
The syntax to use for CommandLineParser is a bit different. You need to put = after the option. Like this:
-l=box.png -r=box_in_scene.png -o=out.png
or
--left=box.png --right=box_in_scene.png --output=out.png
Be sure to put the correct path for the images.