I am having some compilation difficulties when using knitr and tikzDevice. Compilataion works, but I am seeing times upwards of 10 minutes, and this is only increasing as my document grows (I am writing my thesis, and at the moment it takes 10 minutes to compile one chapter, and there are many more chapters to come!).

If I set the device to something other than tikz, there's no problem. Unfortunately I need tikz so that I can use LaTeX in my R plots.

I have a main file main.Rnw which incorporates each chapter as a child document using e.g. \Sexpr{knit_child('chapter3.Rnw')}.

In the chapter files, I include plots etc from R by using e.g. \Sexpr{knit_child('ch3-fig-nitrogenPH.Rnw')} to insert in a figure environment.

My main file specifies the following options for knitr setup:

<<setup, include=FALSE, cache=FALSE>>=

plotTextSize <- 8
cbbPalette<-c("#E69F00", "#56B4E9", "#009E73", "#0072B2", "#D55E00", "#CC79A7")

opts_knit$set(child.command = 'include')

opts_chunk$set(dev = 'tikz', external=TRUE)
opts_chunk$set(fig.align='center', fig.pos='!htbp', fig.width=5.5, fig.height=4, out.width="5.5in", out.height="4in")


options(tikzXelatexPackages = c(

options(tikzMetricPackages = c(

knit_hooks$set(document = function(x) {sub('\\usepackage[]{color}', '\\usepackage{xcolor}', x, fixed = TRUE)})

Finally, one other thing that suggests that I've got something wrong somewhere, is that tikz is ignoring the pointsize arurmet when I try to use it e.g. dev.args=list(pointsize=10) has no effect. See my previous question Setting font size in tikzDevice.

If anyone can point me in the right direction to fix this, I'd be very grateful.

I will try to put together a MWE that replicates the problem.

I am using these packages:

% -*- program: xelatex -*-
\graphicspath{ {images/} }
  • 1
    It is probably a good idea to post the code generated by knitr, most people here are probably not familiar with the output generated from knitr + R, and thus have difficulty generating what ever you are doing and therefore cannot help on the latex issues. – daleif Feb 4 '18 at 16:04
  • 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.