2

I have successfully used grViz in DiagrammR with an R markdown (bookdown) file on R version 3.6.3 that causes an error on another computer with R version 4.0.2. I have "tried everything" that I could think of including re-installing TinyTex and following ALL the options in https://yihui.org/tinytex/r/#debugging

The file compiles OK as HTML in both R versions but PDF causes error in R version 4.0.2

After 3 hours of tests and search I think there is a bug. To test I made a small version of and Rmd (see below) file that does compile to PDF in R 3.6.3 but not in R version 4.0.2 with the warning:

I was unable to find any missing LaTeX packages from the error log Untitled4.log. ! LaTeX Error: Environment grViz undefined.

Error: LaTeX failed to compile Untitled4.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Untitled4.log for more info. Execution halted


SESSION INFO FOR R version 3.6.3 appears at the end of the PDF from this link: https://uwmadison.box.com/s/xkim3gujwemrqau6bur7f8ckl35i9s9f

Here is the RMD file: RMD file is also on this link: 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     

EDIT #1

I checked the .tex file that is created. It seems that under R 4.0.2 the .tex file contains commands that are not created in R 3.6.3. For example here is the result for R 4.0.2:

\begin{figure}

\hypertarget{htmlwidget-7447954648696f078221}{}
\begin{grViz}

\end{grViz}

Flow of information.

\end{figure}

So a \begin{grViz} and an \end{grViz} are created, but nothing in between the 2.

I modified the YAML to run in R 3.6.3 to keep the .tex file

---
title: "Untitled4-R3.6.3"
output:
  pdf_document:
    keep_tex: true
always_allow_html: true
---

In the resulting .tex file there are no command \begin{grViz} and an \end{grViz} so the problem is connected to that aspect it seems. In R 3.6.3 the code is simpler and simply includes a file created in a subfolder Untitled4_files/figure-latex/flowofinformation-1 that is probably a PDF and the folder must be temporary as I cannot find it:

\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}

Therefore the new addition of \begin{grViz} and an \end{grViz} seem to cause the issue, but I have no idea where they come from. In a simple example like this one there is no user-defined preamble.tex file of any sort...

EDIT 2

I think that I'll have to request help further from Yihui on GitHub so here is the fun::session_info for R 4.0.2. First just for Tinytex and then for all:

> 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      
> 

and for all:

> 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        
> 
jys
  • 121
  • 7
  • 1
    I crossposted to https://github.com/yihui/tinytex/issues/230 and made many more attempts to compare output. In fact the error is reproducible in Linux (by using Docker) and in Windows 10 the PDF is created BUT it does not contain the DiagrammeR drawing which defeats the purpose. I am not sure if any one else is seing these posts or is using DiagrammeR these days? – jys Aug 05 '20 at 03:03

1 Answers1

1

SOLVED thank to Yihui's answer. Problem was due to some changes in Markdown. See his answer in https://github.com/yihui/tinytex/issues/230 where you can also see all the tests I conducted before that.

SUMMARY if you have this problem:

  1. update with remotes::install_github('rstudio/rmarkdown')
  2. Also run webshot::install_phantomjs()

After that the PDF is created and the \grViz environment no longer is part of the .tex file.

The answer arrived after I had already also crossposted on the DiagrammeR issue page at https://github.com/rich-iannone/DiagrammeR/issues/409

jys
  • 121
  • 7