Failed to get tikzDevice to work

I have a problem with tikzDevice . I use the latest versions of R (with the latest packages knitr and tikzDevice ) and RStudio , updated TeX Live binaries until 2015 (and I think I have all the necessary packages). When I try to display graphics on tikzDevice , compilation freezes. Other graphics devices such as PDF or CairoPNG work without problems.

As an example, I tried to compile simple code from RStudio with XeLaTeX (installed as the default LaTeX compiler RStudio ) by default, but it hangs forever after using the TikZ score dictionary. I see that compilation actually creates a file with the extension .tikz in the "figure" folder, which can be compiled if I run XeLaTeX on it.

I have attached the full log below from the output panel of the RStudio console 'Compile PDF' while it freezes:

 Le chargement an cessit  le package : knitr processing file: test.Rnw |............. | 20% ordinary text without R code |.......................... | 40% label: setup (with options) List of 2 $ include: logi FALSE $ cache : logi FALSE |....................................... | 60% ordinary text without R code |.................................................... | 80% label: fig1 (with options) List of 3 $ eval: logi TRUE $ echo: logi FALSE $ dev : chr "tikz" Creating new TikZ metrics dictionary at: test-tikzDictionary Using TikZ metrics dictionary at: test-tikzDictionary Le chargement an cessit  le package : knitr processing file: knitr-graphics.Rnw |.. | 2% ordinary text without R code |... | 5% label: setup (with options) List of 2 $ include: logi FALSE $ cache : logi FALSE |..... | 7% inline R code fragments |...... | 10% label: test-plot (with options) List of 1 $ eval: logi FALSE |........ | 12% ordinary text without R code |.......... | 15% label: pdf-dev (with options) List of 4 $ ref.label: chr "test-plot" $ dev : chr "pdf" $ out.width: chr "\\linewidth" $ echo : logi FALSE |........... | 17% ordinary text without R code |............. | 20% label: png-dev (with options) List of 4 $ ref.label: chr "test-plot" $ dev : chr "png" $ out.width: chr "\\linewidth" $ echo : logi FALSE |.............. | 22% ordinary text without R code |................ | 24% label: cairo-png-dev (with options) List of 4 $ ref.label: chr "test-plot" $ dev : chr "CairoPNG" $ out.width: chr ".5\\linewidth" $ echo : logi FALSE |................. | 27% ordinary text without R code |................... | 29% label: two-high (with options) List of 3 $ fig.width : num 3 $ fig.height: num 2.5 $ out.width : chr ".49\\linewidth" Using TikZ metrics dictionary at: knitr-graphics-tikzDictionary 

And an excerpt from tikzStringWidthCalc.log found in the temporary folder R:

 This is XeTeX, Version 3.14159265-2.6-0.99992 (TeX Live 2015/W32TeX) (preloaded format=xelatex 2015.6.25) 1 JUL 2015 13:45 entering extended mode restricted \write18 enabled. %&-line parsing enabled. **c:/Users/guyader/AppData/Local/Temp/RtmpqwmJYG/tikzStringWidthCalc.tex (c:/Users/guyader/AppData/Local/Temp/RtmpqwmJYG/tikzStringWidthCalc.tex LaTeX2e <2015/01/01> Babel <3.9l> and hyphenation patterns for 4 languages loaded. (c:/texlive/2014/texmf-dist/tex/latex/base/article.cls Document Class: article 2014/09/29 v1.4h Standard LaTeX document class (c:/texlive/2014/texmf-dist/tex/latex/base/size10.clo File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option) ) \ c@part =\count79 \ c@section =\count80 \ c@subsection =\count81 \ c@subsubsection =\count82 \ c@paragraph =\count83 \ c@subparagraph =\count84 \ c@figure =\count85 \ c@table =\count86 \abovecaptionskip=\skip41 \belowcaptionskip=\skip42 \bibindent=\dimen102 ) (c:/texlive/2014/texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty (c:/texlive/2014/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty (c:/texlive/2014/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty (c:/texlive/2014/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.tex \ pgfutil@everybye =\toks14 \ pgfutil@tempdima =\dimen103 \ pgfutil@tempdimb =\dimen104 (c:/texlive/2014/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-lists.tex) ) (c:/texlive/2014/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def \ pgfutil@abb =\box26 

[...]

 LaTeX Font Info: Redeclaring math symbol \Omega on input line 30. LaTeX Font Info: Redeclaring math symbol \mathdollar on input line 30. LaTeX Font Info: Redeclaring symbol font `operators' on input line 30. LaTeX Font Info: Encoding `OT1' has changed to `EU1' for symbol font (Font) `operators' in the math version `normal' on input line 30. LaTeX Font Info: Overwriting symbol font `operators' in version `normal' (Font) OT1/cmr/m/n --> EU1/lmr/m/n on input line 30. LaTeX Font Info: Encoding `OT1' has changed to `EU1' for symbol font (Font) `operators' in the math version `bold' on input line 30. LaTeX Font Info: Overwriting symbol font `operators' in version `bold' (Font) OT1/cmr/bx/n --> EU1/lmr/m/n on input line 30. LaTeX Font Info: Overwriting symbol font `operators' in version `normal' (Font) EU1/lmr/m/n --> EU1/lmr/m/n on input line 30. LaTeX Font Info: Overwriting math alphabet `\mathit' in version `normal' (Font) OT1/cmr/m/it --> EU1/lmr/m/it on input line 30. LaTeX Font Info: Overwriting math alphabet `\mathbf' in version `normal' (Font) OT1/cmr/bx/n --> EU1/lmr/bx/n on input line 30. LaTeX Font Info: Overwriting math alphabet `\mathsf' in version `normal' (Font) OT1/cmss/m/n --> EU1/lmss/m/n on input line 30. LaTeX Font Info: Overwriting math alphabet `\mathtt' in version `normal' (Font) OT1/cmtt/m/n --> EU1/lmtt/m/n on input line 30. LaTeX Font Info: Overwriting symbol font `operators' in version `bold' (Font) EU1/lmr/m/n --> EU1/lmr/bx/n on input line 30. LaTeX Font Info: Overwriting math alphabet `\mathit' in version `bold' (Font) OT1/cmr/bx/it --> EU1/lmr/bx/it on input line 30. LaTeX Font Info: Overwriting math alphabet `\mathsf' in version `bold' (Font) OT1/cmss/bx/n --> EU1/lmss/bx/n on input line 30. LaTeX Font Info: Overwriting math alphabet `\mathtt' in version `bold' (Font) OT1/cmtt/m/n --> EU1/lmtt/bx/n on input line 30. tikzTeXWidth=4.80003pt ! Missing \endgroup inserted. <inserted text> \endgroup l.37 \@@end Here is how much of TeX memory you used: 23160 strings out of 495610 491023 string characters out of 6186855 478788 words of memory out of 5000000 26156 multiletter control sequences out of 15000+600000 6670 words of font info for 20 fonts, out of 8000000 for 9000 14 hyphenation exceptions out of 8191 55i,5n,54p,10417b,529s stack positions out of 5000i,500n,10000p,200000b,80000s No pages of output. 

Also, if I run the knit("test.Rnw") command knit("test.Rnw") from the R console, I get the following:

 processing file: test.Rnw |............. | 20% ordinary text without R code |.......................... | 40% label: setup (with options) List of 2 $ include: logi FALSE $ cache : logi FALSE |....................................... | 60% ordinary text without R code |.................................................... | 80% label: fig1 (with options) List of 3 $ eval: logi TRUE $ echo: logi FALSE $ dev : chr "tikz" Using TikZ metrics dictionary at: test-tikzDictionary Quitting from lines 14-17 (test.Rnw) Error: failed to compile figure/graphics-fig1-1.tikz to PDF In addition: Warning message: running command '"C:\texlive\2014\bin\win32\xelatex.exe" "graphics-fig1-1.tikz"' had status 1 

Although, if you run XeLaTeX in the .tikz image file from the Windows command line, it will successfully compile to PDF.

Here is my sessionInfo() :

 R version 3.2.1 (2015-06-18) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252 [4] LC_NUMERIC=C LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.2.1 

Following my problem with tikzDevice , the only workaround I found was to output the graphics to another device, for example png, adding usepackage{tikz} to the preamble, calling tikz() inside the code snippet and \input{} result .tex looks like this :

 \documentclass{article} \usepackage{tikz} \begin{document} <<setup, include=FALSE, cache=FALSE>>= library(knitr) library(tikzDevice) options(formatR.arrow=TRUE,width=50,tikzDefaultEngine='xetex') opts_chunk$set(fig.path='figure/graphics-', cache.path='cache/graphics-', fig.align='center', dev='png', fig.width=5, fig.height=5, fig.show='hold', cache=TRUE, par=TRUE, concordance=TRUE) @ \begin{figure} <<fig1,eval=TRUE,echo=FALSE>>= library(ggplot2) setwd("~/") td <- getwd() tf <- file.path(td,'fig1.tex') tikz(tf, standAlone=F, bareBones=F) qplot(displ, hwy, data = mpg, colour = factor(cyl)) dev.off() @ \input{fig1.tex} \end{figure} \end{document} 

This way I can get font consistency from using tikz, but it would be much easier to work with tikzDevice() .

+6
source share

All Articles