使用knitr在tikzDevice中出错

时间:2016-10-06 10:44:51

标签: r knitr tikzdevice

似乎与knitr和/或tikzDevice和/或R的新版本存在冲突。在任何情况下,我都无法继续工作。

这是一个MWE:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{tikz}

<<setup, include=FALSE, cache=FALSE>>=
  library(knitr)

  opts_chunk$set(fig.path='figure/graphics-', 
                 cache.path='cache/graphics-', 
                 fig.align='center',
                 dev='tikz'
                )
@

\begin{document}
blop

<<>>=
plot(1:10)  
@

\end{document}

这将返回错误:

Quitting from lines 21-22 (testTikz.Rnw)  Error in
tikzDevice::tikz(..., packages = c("\n\\nonstopmode\n", packages,  :  
unused argument (verbose = FALSE) Calls: knit ... chunk_device ->
dev_new -> do.call -> <Anonymous> -> <Anonymous>

Execution halted

我正在使用R版本3.3.1,knitr_1.14和tikzDevice_0.8.1

修改

我通过在github上分配knitr repo来修改tikz_dev函数来删除verbose参数。我现在收到以下错误:

Error in (function (file = ifelse(onefile, "./Rplots.tex", "./Rplot%03d.tex"),  :
Graphics API version mismatch
Calls: knit ... do.call -> <Anonymous> -> do.call -> <Anonymous> -> .External

1 个答案:

答案 0 :(得分:0)

我通过添加.Rprofile几行并将tikzDevice更新为版本tikzDevice_0.10-1

来解决此问题
options(tikzMetricPackages = c("\\usepackage[utf8]{inputenc}",
                               "\\usepackage[T1]{fontenc}",
                               "\\usetikzlibrary{calc}",                   
                               "\\usepackage{amssymb}"
                              )
       )