我已经在 DiagrammR 中成功使用了 grViz,并在 R 版本 3.6.3 上使用了 R markdown(bookdown)文件,这导致另一台 R 版本为 4.0.2 的计算机上出现错误。我已经“尝试了一切”,包括重新安装 TinyTex 并遵循https://yihui.org/tinytex/r/#debugging中的所有选项
该文件在两个 R 版本中都可以编译为 HTML,但 PDF 在 R 版本 4.0.2 中导致错误
经过 3 小时的测试和搜索,我认为有一个错误。为了测试,我制作了一个小版本的 Rmd(见下文)文件,它在 R 3.6.3 中编译为 PDF,但在 R 版本 4.0.2 中编译为 PDF,并带有警告:
我无法从错误日志 Untitled4.log 中找到任何丢失的 LaTeX 包。!LaTeX 错误:环境 grViz 未定义。
错误:LaTeX 无法编译 Untitled4.tex。调试技巧见 https://yihui.org/tinytex/r/#debugging。有关详细信息,请参阅 Untitled4.log。执行停止
R 版本 3.6.3 的会话信息显示在此链接的 PDF 末尾: https ://uwmadison.box.com/s/xkim3gujwemrqau6bur7f8ckl35i9s9f
这是 RMD 文件:RMD 文件也在此链接上:https ://uwmadison.box.com/s/4knl7y3f7yti8ibivfjex7qdv3ez8a11
---
title: "Untitled4"
output: pdf_document
always_allow_html: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(tinytex.verbose = TRUE)
```
# Test grViz
```{r flowofinformation, engine='R', eval=TRUE, echo=FALSE, fig.cap='Flow of information.', out.width = if (knitr:::is_html_output()) '100%' else '90%'}
DiagrammeR::grViz("
digraph dot {
graph [layout = dot
rankdir = LR]
node [shape = 'rectangle', style = filled, fillcolor = pink]
DNA, RNA, Protein
DNA -> {RNA}
RNA -> {Protein}
edge [color = gray, arrowtail = left, style = dashed ]
RNA -> {DNA}
}")
```
```{r}
sessionInfo()
```
SESSION INFO for version R 4.0.2:
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
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] bookdown_0.20 visNetwork_2.0.9 digest_0.6.25
[4] jsonlite_1.7.0 magrittr_1.5 evaluate_0.14
[7] rlang_0.4.7 rmarkdown_2.3 DiagrammeR_1.0.6.1
[10] RColorBrewer_1.1-2 tools_4.0.2 glue_1.4.1
[13] htmlwidgets_1.5.1 tinytex_0.24 xfun_0.15
[16] yaml_2.2.1 compiler_4.0.2 htmltools_0.5.0
[19] knitr_1.29
编辑#1
我检查了.tex
创建的文件。似乎在 R 4.0.2 下,该.tex
文件包含未在 R 3.6.3 中创建的命令。例如,这里是 R 4.0.2 的结果:
\begin{figure}
\hypertarget{htmlwidget-7447954648696f078221}{}
\begin{grViz}
\end{grViz}
Flow of information.
\end{figure}
因此创建了 a\begin{grViz}
和 an \end{grViz}
,但在 2 之间没有任何内容。
我修改了 YAML 以在 R 3.6.3 中运行以保留.tex
文件
---
title: "Untitled4-R3.6.3"
output:
pdf_document:
keep_tex: true
always_allow_html: true
---
在生成的.tex
文件中没有命令\begin{grViz}
,\end{grViz}
因此问题似乎与该方面有关。在 R 3.6.3 中,代码更简单,只包含在Untitled4_files/figure-latex/flowofinformation-1
可能是 PDF 的子文件夹中创建的文件,并且该文件夹必须是临时的,因为我找不到它:
\hypertarget{test-grviz}{%
\section{Test grViz}\label{test-grviz}}
\begin{figure}
\includegraphics[width=0.9\linewidth]{Untitled4_files/figure-latex/flowofinformation-1} \caption{Flow of information.}\label{fig:flowofinformation}
\end{figure}
因此,新添加的\begin{grViz}
和 an\end{grViz}
似乎导致了这个问题,但我不知道它们来自哪里。在像这样的一个简单示例中,没有preamble.tex
任何类型的用户定义文件...
编辑 2
我想我必须在 GitHub 上向 Yihui 寻求进一步的帮助,所以这里是fun::session_info
R 4.0.2。首先只是为了Tinytex
,然后是为了所有人:
> xfun::session_info('tinytex')
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6, RStudio 1.3.959
Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8
Package version:
graphics_4.0.2 grDevices_4.0.2 stats_4.0.2 tinytex_0.24 tools_4.0.2
utils_4.0.2 xfun_0.15
>
对于所有人:
> xfun::session_info()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6, RStudio 1.3.959
Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8
Package version:
assertthat_0.2.1 backports_1.1.8 base64enc_0.1.3 BH_1.72.0.3
bookdown_0.20 callr_3.4.3 cli_2.0.2 clipr_0.7.0
colorspace_1.4.1 compiler_4.0.2 crayon_1.3.4 desc_1.2.0
DiagrammeR_1.0.6.1 digest_0.6.25 downloader_0.4 dplyr_1.0.0
ellipsis_0.3.1 evaluate_0.14 fansi_0.4.1 farver_2.0.3
generics_0.0.2 ggplot2_3.3.2 glue_1.4.1 graphics_4.0.2
grDevices_4.0.2 grid_4.0.2 gridExtra_2.3 gtable_0.3.0
highr_0.8 hms_0.5.3 htmltools_0.5.0 htmlwidgets_1.5.1
igraph_1.2.5 influenceR_0.1.0 isoband_0.2.2 jsonlite_1.7.0
knitr_1.29 labeling_0.3 lattice_0.20.41 lifecycle_0.2.0
magrittr_1.5 markdown_1.1 MASS_7.3.51.6 Matrix_1.2.18
methods_4.0.2 mgcv_1.8.31 mime_0.9 munsell_0.5.0
nlme_3.1.148 pillar_1.4.6 pkgbuild_1.0.8 pkgconfig_2.0.3
pkgload_1.1.0 praise_1.0.0 prettyunits_1.1.1 processx_3.4.3
ps_1.3.3 purrr_0.3.4 R6_2.4.1 RColorBrewer_1.1-2
Rcpp_1.0.5 readr_1.3.1 rlang_0.4.7 rmarkdown_2.3
rprojroot_1.3.2 rstudioapi_0.11 scales_1.1.1 splines_4.0.2
stats_4.0.2 stringi_1.4.6 stringr_1.4.0 testthat_2.3.2
tibble_3.0.3 tidyr_1.1.0 tidyselect_1.1.0 tinytex_0.24
tools_4.0.2 utf8_1.1.4 utils_4.0.2 vctrs_0.3.1
viridis_0.5.1 viridisLite_0.3.0 visNetwork_2.0.9 withr_2.2.0
xfun_0.15 yaml_2.2.1
>