2017-01-24 32 views
1

我想在R Markdown中使用tufte_handout生成tikz圖我正在RStudio中運行此工具。這裏是我的sessionInfo()在tufte_handout中使用Tarkz與RMarkdown

R version 3.3.2 (2016-10-31) 
    Platform: x86_64-apple-darwin16.1.0 (64-bit) 
    Running under: macOS Sierra 10.12.2 

    locale: 
    [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 

    attached base packages: 
    [1] stats  graphics grDevices utils  datasets methods base  

    loaded via a namespace (and not attached): 
    [1] backports_1.0.4 magrittr_1.5 tufte_0.2  rprojroot_1.1 htmltools_0.3.5 tools_3.3.2  yaml_2.1.14  Rcpp_0.12.8  
    [9] stringi_1.1.2 rmarkdown_1.3 knitr_1.15.1 stringr_1.1.0 digest_0.6.11 evaluate_0.10 

我的例子(沒有工作)是:

 --- 
    title: "TikzTest" 
    output: 
     tufte::tufte_handout: default 
    --- 

    This is a test of the R Markdown tufte_handout.^[This is a sidenote in the tufte_handout] To use the tikz package, you have to include this code chunk: 
    ```{r setup, include=FALSE} 
    knitr::opts_chunk$set(echo = TRUE,dev = 'tikz') 
    library(tikzDevice) 
    ``` 

    But it doesn't work?: 
    ```{r,engine='tikz'} 
    \begin{tikzpicture}[line width=0.05cm] 

    \node [align=center] (x) at (0,0) {$X$}; 
    \node [align=center] (y) at (2.55,0) {$Y$}; 

    \begin{scope}[line width=.05cm,shorten >= 5pt, shorten <= 5pt] 
    \draw[->,color=black] (x) to (y); 
    \end{scope} 
    \end{tikzpicture} 
    ``` 

當我編織,我得到了以下錯誤:

 Error in tools::texi2dvi(texf, pdf = !to_svg, clean = TRUE) : 
     Running 'texi2dvi' on './tikz145322b8f468.tex' failed. 
    Messages: 
    sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory 
    Calls: <Anonymous> ... call_block -> block_exec -> in_dir -> engine -> <Anonymous> 
    Execution halted 

我有MacTEX都-2016分發安裝

回答

0

我沒有Mac,但我收到了同樣的錯誤,你是w運行您提供的代碼。爲了解決這個問題,我所要做的就是走這條線:

line:knitr::opts_chunk$set(echo = TRUE,dev = 'tikz')

並將其更改爲以下內容:

knitr::opts_chunk$set(echo = TRUE)

隨着這種變化,它的工作只是什麼罰款我想象你正在尋找的輸出。希望這也可以在Mac上運行。

+0

謝謝,但沒有運氣。即使我從chunk_set選項中刪除'dev ='tikz'',我仍然會得到相同的錯誤。 – user1849779