I have reported this with example in Stack Overflow
In summary when using grViz in DiagrammR the compilation in the Latex file contains:
\begin{grViz}
\end{grViz}
with just blank in between, and this prevents the PDF to be created because, as reported by RStudio:
I was unable to find any missing LaTeX packages from the error log Untitled4.log.
! LaTeX Error: Environment grViz undefined.
But this only happens under R.4.0.2 and not with R.3.6.3 for which the .tex file does not contain the {grViz} statements.
On Stack Overflow I have posted the example I used to test this, it works in Rv3.6.3 but not Rv4.0.2.
TinyTex cannot determine any missing package, and while this may not be a bug per se it may mean that some underlying "default" .tex information needs to be updated in RStudio (as far as I can understand how things could be..)
I was able to complete the bookdown material I was working on with another computer that remained at Rv3.6.3 but I find it important to have this looked at.
Thank you!
Jean-Yves Sgro
By filing an issue to this repo, I promise that
xfun::session_info('tinytex'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/tinytex').I understand that my issue may be closed if I don't fulfill my promises.
I try to run your example in the SO question, but it works for both 3.6.3 and 4.0.2 on my computer.
I did a remotes::update_packages(c("DiagrammeR", "tinytex", "rmarkdown", "knitr")) in both R session to get the last version of everything.
The grViz part gives in the tex file this:
\begin{figure}
\includegraphics[width=0.9\linewidth]{test_files/figure-latex/flowofinformation-1} \caption{Flow of information.}\label{fig:flowofinformation}
\end{figure}
with both R version.
There may be something else that differs between you two R session. I am not sure this is with tinytex though... 🤔
You mention bookdown. Are you example supposed to be run in bookdown ? Can you confirm that your Rmd document (the one below) does not render correctly in one of your R session ?
This document from your SO post
title: "Untitled4"
output:
pdf_document:
keep_tex: 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}
}")
````
Thank you (et merci) for your reply.
I confirm that the test document does not render in my installation of R 4.0.2.
Version 1.3.1056R4.0 from:> .Library
[1] "/Library/Frameworks/R.framework/Resources/library"
And installed again from a fresh CRAN download of R 4.0.2 (version R-4.0.2 16-52-29-381.pkg)
I have checked on the system and removed old traces of Tex option that might have interfered with TinyTex following uninstall instructions from https://tug.org/mactex/uninstalling.html
With this fresh install I just added the minimal number of required packages starting with knitr. I then just addedDiagrammr(but that installs a large number of pckages) and thetinytex` following Yihui instructions on https://yihui.org/tinytex/
install.packages('tinytex')
tinytex::install_tinytex()
To follow your instructions I also installed remotes and then ran:
remotes::update_packages(c("DiagrammeR", "tinytex", "rmarkdown", "knitr"))
As the test files lives within an RProj directory I removed rm -r .Rproj.user to make sure nothing was there that could cause trouble.
I reran remotes::install_github('yihui/tinytex') to be sure.
The fun session for tinytex now read:
> 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.1056
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.1 tools_4.0.2 utils_4.0.2
xfun_0.15
The extended error now reads:
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
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.
Switching from pdfLaTeX to XeLaTeX in the RStudio preferences (Sweave) does not make a difference.
In the saved .tex file the code for the figure reads:
\hypertarget{test-grviz}{%
\section{Test grViz}\label{test-grviz}}
\begin{figure}
\hypertarget{htmlwidget-260f161298f3b2544b4a}{}
\begin{grViz}
\end{grViz}
The .tex file therefore gets created.
In the .log file all is well until the end where it reports the error as:
! LaTeX Error: Environment grViz undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.115 \begin{grViz}
Here is how much of TeX's memory you used:
10802 strings out of 482854
155404 string characters out of 5955382
400382 words of memory out of 5000000
25985 multiletter control sequences out of 15000+600000
562349 words of font info for 50 fonts, out of 8000000 for 9000
14 hyphenation exceptions out of 8191
43i,4n,37p,243b,290s stack positions out of 5000i,500n,10000p,200000b,80000s
! ==> Fatal error occurred, no output PDF file produced!
It is baffling that even starting from scratch the error came back.
Any suggestion of where else to look or update?
Thank you!
JYS
Error is reproducible in Docker container.
! LaTeX Error: Environment grViz undefined.
I was unable to find any missing LaTeX packages from the error log test1.log.
Attached: test1.zip containing .Rmd .tex and .log files.
Thank you for your previous answer. On the Mac where this happened I have done many "things" without success such as: remove TinyTex, re-install MacTex, update pandoc with brew etc. Nothing made any change. However, tonight I was able to reproduce the error within a Docker container using minimally https://hub.docker.com/r/rocker/r-base (for R 4.0.2) as there is no pre-made official RStudio version that I could find that has R.4.0.2.
I used the manual commands to install knitr, rmarkdown, DiagrammeR... using install.packages()
I installed pandoc on the Linux OS which is "linuxkit."
The saved container ends-up being 1.4Gb.
root@5e3df87b4d10:/# uname -a
Linux 5e3df87b4d10 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 GNU/Linux
I created a new minimal .Rmd file called test1.Rmd:
title: "Test1"
output:
pdf_document:
keep_tex: true
html_document:
toc: true
```{r, include=FALSE}
options(tinytex.verbose = TRUE)
# Test DiagrammeR
FROM https://bookdown.org/yihui/rmarkdown-cookbook/diagrams.html
```{r}
library(DiagrammeR)
DiagrammeR::grViz("digraph {
graph [layout = dot, rankdir = TB]
node [shape = rectangle]
rec1 [label = 'Step 1. Wake up']
rec2 [label = 'Step 2. Write code']
rec3 [label = 'Step 3. ???']
rec4 [label = 'Step 4. PROFIT']
# edge definitions with the node IDs
rec1 -> rec2 -> rec3 -> rec4
}",
height = 500)
Done
````
The command
rmarkdown::render("test1.Rmd", "pdf_document")
gives the same error as I had on the other Mac running R 4.0.2
i.e. ! LaTeX Error: Environment grViz undefined.
What's puzzling is that the extended log says:
I was unable to find any missing LaTeX packages from the error log test1.log.
> rmarkdown::render("test1.Rmd", "pdf_document")
processing file: test1.Rmd
|.............. | 20%
ordinary text without R code
|............................ | 40%
label: unnamed-chunk-1 (with options)
List of 1
$ include: logi FALSE
|.......................................... | 60%
ordinary text without R code
|........................................................ | 80%
label: unnamed-chunk-2
|......................................................................| 100%
ordinary text without R code
output file: test1.knit.md
/usr/bin/pandoc +RTS -K512m -RTS test1.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output test1.tex --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --lua-filter /usr/local/lib/R/site-library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /usr/local/lib/R/site-library/rmarkdown/rmd/lua/latex-div.lua --variable 'geometry:margin=1in'
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
I was unable to find any missing LaTeX packages from the error log test1.log.
! LaTeX Error: Environment grViz undefined.
Error: LaTeX failed to compile test1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test1.log for more info.
>
The saved .tex file is 145 lines and seems that it would have the necessary instructions to make the graphics
The very end of the test1.tex file says:
\end{Shaded}
\hypertarget{htmlwidget-086f88a7f6bd0b1a96f1}{}
\begin{grViz}
\end{grViz}
Done
\end{document}
If I comment out the \begin{grViz} and \end{grViz} lines the PDF document is produced with command tinytex::pdflatex('test1.tex')
but without the drawing.
Here is the new output for xfun since this is a different system:
> xfun::session_info('tinytex')
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux bullseye/sid
Locale:
LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
LC_PAPER=en_US.UTF-8 LC_NAME=C
LC_ADDRESS=C LC_TELEPHONE=C
LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
Package version:
graphics_4.0.2 grDevices_4.0.2 stats_4.0.2 tinytex_0.25
tools_4.0.2 utils_4.0.2 xfun_0.16
>
The docker environment as I understand it is Linux-based and therefore none of the Mac stuff would be influencing this result.
This is very puzzling... Any one has any idea?
Thanks!
JYS
Also reproducible in rocker/rstudio Docker
Steps:
1) Download from https://hub.docker.com/r/rocker/rstudio/tags using 4.0.2 TAG:
docker pull rocker/rstudio:4.0.2
2) Open Rstudio in web browser according to steps described in https://hub.docker.com/r/rocker/rstudio
docker run --rm -v $(pwd):/data -p 127.0.0.1:8787:8787 -e PASSWORD=xxxxxxx rocker/rstudio
3) Create Rmarkdown file: requires installation of knitr, rmarkdown etc. pandoc is already preinstalled in this docker. Use test1.Rmd again (as previous post)
4) Install DiagrammeR
install.packages("DiagrammeR")
5) Install TinyTex
tinytex::install_tinytex()
6) knit test1.Rmd file (text in previous post, also in attachment)
I was unable to find any missing LaTeX packages from the error log test1.log.
! LaTeX Error: Environment grViz undefined.
The same code is in this file, as expected:
\begin{grViz}
\end{grViz}
Therefore there is a problem to create Graphviz images using DiagrammeR also here.
In conclusion: this is a reproducible error that occurs systematically. I found it on my Mac, then in Docker and then in this other docker (hence under Linux.)
From previous post in Docker using just r-base it is clear that the problem is not with Rstudio. But I cannot find out what the problem is.
Any one has any idea ?
Reproducible also in R v.4.0.0
Using the same method I tried the first R version 4.0.0 to test if the error was particular to 4.0.0.
Using this version:
docker pull rocker/rstudio:4.0.0
The answer is the same: same error. ! LaTeX Error: Environment grViz undefined.
I then found that there is a version of Rstudio in a docker that already has TinyTex already installed as well as all the knitr, markdown etc. packages, also including pandoc. Therefore the only package to install is DiagrammeR which Rstudio suggests.
docker pull rocker/verse:4.0.2
The only diffference with this version is that tinytex is loading a bunch of .sty files but in the end also gives the error:
tlmgr: package log updated: /opt/texlive/texmf-var/web2c/tlmgr.log
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
I was unable to find any missing LaTeX packages from the error log test1.log.
! LaTeX Error: Environment grViz undefined.
Surely other people must be trying to use DiagrammeR and Graphviz and getting that error too?
My next step will be to reboot as a Windows 10 system and see if that occurs there as well...
For now the scores are Errors for R 4.0.0 and 4.0.2
Here is the xfun() output for Docker version rocker/verse:4.0.2:
> xfun::session_info('tinytex')
xfun::session_info('tinytex')
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS, RStudio 1.3.1056
Locale: LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C
LC_PAPER=en_US.UTF-8 LC_NAME=C
LC_ADDRESS=C LC_TELEPHONE=C
LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
Package version: graphics_4.0.2 grDevices_4.0.2 stats_4.0.2 tinytex_0.25 tools_4.0.2 utils_4.0.2 xfun_0.16
Reproducible grViz Error when using DiagrammeR in R version 4.0.x (4.0.0 and 4.0.2 tested in previous posts for Mac/Linux.) but not in version 3.6.3
This post is for WINDOWS 10 test: The grViz diagram is NOT created on the generated PDF. As such there is no error written but the result is still a PDF without the diagram!
The reason there is no error generated is because there the WINDOWS version does not add the following, resulting in the same PDF generated by the .tex generated files on Mac or Linux (docker) when the commands are commented out with % or removed.
\begin{grViz}
\end{grViz}
Bottomline: With or without Environment grViz undefined. error the diagram is not present on the PDF version (but it is on the HTML version) when in R version 4.0.x.
In R 3.6.3 there does not seem to be any htmlwidget but an \includegraphics command to include a PDF from a code chunk. From the .tex file created by R 3.6.3:
\includegraphics{test1_files/figure-latex/unnamed-chunk-2-1.pdf} and indeed there is a directory that was created test1_files containing directory figure-latex and file unnamed-chunk-2-1.pdf which is just the diagram.
Could that be also a major difference in how the process of creating the .tex and then .pdf
I append here the 4 .tex files for Linux, MacOS. Windows made with R 4.0.x and one for R 3.6.3 (Made with Mac) together with the test1.Rmd file in a ZIP file together with the folder and PDF created by 3.6.3:
Content:
├── test1-MacOS-MOjave-4.0.2.tex
├── test1-MacOS-Mojave-R.3.6.3..pdf
├── test1-MacOS-Mojave-R.3.6.3.tex
├── test1-Windows-10-R4.0.2.tex
├── test1-docker-rocker-vers-4.0.2.tex
├── test1.Rmd
└── test1_files
└── figure-latex
└── unnamed-chunk-2-1.pdf
I didn't read all your posts above carefully, but I'm reasonably sure that this issue is irrelevant to tinytex, because tinytex definitely doesn't generate any LaTeX environments like grViz. All it does is compile .tex to .pdf. You reported this issue to this repo because tinytex failed to compile .tex to .pdf, but I don't think the root cause is in this package.
My blind guess is that remotes::install_github('rstudio/rmarkdown') might fix your problem (due to this change https://github.com/rstudio/rmarkdown/commit/b2cff70c523b1bd6a7269fc8c28ee9ca9f51c71a).
I have now added a post on the DiagrammeR issue page which I just discovered: https://github.com/rich-iannone/DiagrammeR/issues/409
Thank you so much yihui, I just found your message after I posted just now on the DiagrammeR issues page https://github.com/rich-iannone/DiagrammeR/issues/409
I was extremely curious about the root-cause, and it seems that tinytex is not it, thanks for clarifying what tinytex actually does in this process.
This also would explain why the .tex files are different in Mac/Linux/Windows even with the same R version and the same tinytex version.
I am going to try your suggestion....... (Downloading Docker rocker/verse to test)
Your suggestion to update with remotes::install_github('rstudio/rmarkdown') mostly worked. The error is gone but the .tex and .pdf files contained a comment about phantomjs and I also ran the suggested command:
webshot::install_phantomjs()
Now the final .tex file no longer has the grViz commands and does now contain a command just like it was in R 3.6.3: \includegraphics{test_files/figure-latex/unnamed-chunk-2-1.pdf}
THANK YOU ! Yihui... I really appreciate your input so late at night... (and hello from Madison WI)
I will cross-post the answer to the other threads I have started. Wonderful!
Good to know that my guess was correct! Thanks for testing!
Most helpful comment
I didn't read all your posts above carefully, but I'm reasonably sure that this issue is irrelevant to tinytex, because tinytex definitely doesn't generate any LaTeX environments like
grViz. All it does is compile .tex to .pdf. You reported this issue to this repo because tinytex failed to compile.texto.pdf, but I don't think the root cause is in this package.My blind guess is that
remotes::install_github('rstudio/rmarkdown')might fix your problem (due to this change https://github.com/rstudio/rmarkdown/commit/b2cff70c523b1bd6a7269fc8c28ee9ca9f51c71a).