knitr编译在使用tikz设备时挂起

时间:2015-10-16 12:42:15

标签: r knitr tikz

我目前正在Windows 7上首次尝试使用Rstudio(0.99.486),R(3.2.2),Tex Live 2015,knitr(1.11)和tikzDevice(0.8.1)进行可重复性研究

简而言之,当我使用dev =' pdf'我编译没有问题,但是,一旦我设置任何块使用dev =' tikz',编译就会挂起(我已经将MWE留下了一个多小时)。

\documentclass{article}
\begin{document}

<<setup, include=F, cache=F>>=
library(knitr)
@

Here is some text.
Next is a pdf plot:

<<test1, dev='pdf'>>=
plot(c(1,2),c(2,3))
@

Next is the same but using tikz:

<<test2, dev='tikz'>>=
plot(c(1,2),c(2,3))
@

\end{document}

如果我将最后一个块更改为使用dev =&#39; pdf&#39;而不是tikz,它将编译好。如果它被设置为tikz,我得到以下内容 - 但它永远不会完成。

Loading required package: knitr


processing file: MWE.Rnw
  |.........                                                        |  14%
  ordinary text without R code

  |...................                                              |  29%
label: setup (with options) 
List of 2
 $ include: symbol F
 $ cache  : symbol F

  |............................                                     |  43%
  ordinary text without R code

  |.....................................                            |  57%
label: test1 (with options) 
List of 1
 $ dev: chr "pdf"

  |..............................................                   |  71%
  ordinary text without R code

  |........................................................         |  86%
label: test2 (with options) 
List of 1
 $ dev: chr "tikz"

Using TikZ metrics dictionary at:
    MWE-tikzDictionary

如果我只是使用tikz()手动在R中绘图,它可以正常工作,所以我假设问题与knitr + tikzDevice有关。我有点茫然,任何帮助都会受到赞赏。

提前致谢。

编辑:

奇怪的是,如果我在序言中加上\ usepackage {tikz},它现在已经过了上面的阶段,但仍然失败了。即使我然后注释掉\ usepackage {tikz}行!我认为它必须在第一次适当地生成字典,并且不需要更新它。无论如何,我现在收到很多消息,最后一部分是:

!  ==> Fatal error occurred, no output PDF file produced!
Quitting from lines 21-22 (MWE.Rnw) 
Error in getMetricsFromLatex(TeXMetrics) : 
TeX was unable to calculate metrics for the following string
or character:

    m

Common reasons for failure include:
  * The string contains a character which is special to LaTeX unless
escaped properly, such as % or $.
  * The string makes use of LaTeX commands provided by a package and
the tikzDevice was not told to load the package.

The contents of the LaTeX log of the aborted run have been printed above,
it may contain additional details as to why the metric calculation failed.
Calls: knit ... print.recordedplot -> replayPlot -> <Anonymous> -> getMetricsFromLatex

Execution halted

我原本没有把这个打包电话放在序言中,因为knitr主页上的Graphics Demo没有它;并且,阅读剩下的消息,knitr似乎无论如何都会自动加载它。不知道为什么那会改变一切。

我认为这可能是一个类似的问题:Unable to get tikzDevice to work

哦,并使用推荐的解决方案来解决类似的声音问题:

devtools::install_github( 'yihui/tikzDevice' )

似乎也不起作用。现在它挂起来了(无论是\ usepackage {tikz}是否在序言中):

label: test2 (with options) 
List of 1
 $ dev: chr "tikz"

0 个答案:

没有答案