4

On my friends Windows pc, then running any type of plots with knitr outputting with dev='tikz' I get an error.

It works with dev='pdf'.

It does output the file "foo-1.tikz" and this can be compiled fine on its own, however when using knitr by

knit("temp.Rnw")

then it

processing file: temp.Rnw
  |......................                                           |  33%
  ordinary text without R code

  |...........................................                      | 67%
label: foo (with options)
List of 2
$ fig.height: num 4
$ dev       : chr "tikz"

Creating new TikZ metrics dictionary at:
    temp-tikzDictionary
Using TikZ metrics dictionary at:
    temp-tikzDictionary
Quitting from lines 9-13 (temp.Rnw)
Error: failed to compile figure/foo-1.tikz to PDF

I have no idea what can be wrong and where to look for a solution. Somehow knitr cannot find out how to call pdflatex or something.

Can anyone give my a hint how to solve this?

1 Answers1

0

I have the same problem.

I've found a workaround thanks to this report on the knitr Github repo.

Set the chunk option external=FALSE. With this option, knitr does not run the compilation of the files xxx.tikz. Instead, it includes them in the LaTeX file like this:

\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}
\input{figure/myplot-1.tikz}
\end{knitrout}

The problem with this way is that the chunk option out.width is ignored, and the figures can be so big that they go in the margins and even beyond.

But you can control the figure size like this in the Rnw, by using scalebox:

\begin{figure}
\centering
\scalebox{0.5}{
<<myplot, echo=FALSE, fig.width=10, fig.height=6, dev='tikz', external=FALSE>>=
…….
@
}
\end{figure}

Oddly, the dev.args chunk option causes a crash (I tried e.g. dev.args=list(width=3,height=3) to set the dimensions), while it is supposed to pass the arguments to the device.

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225