0

Goal: To create a pdf with R markdown that includes a DiagrammeR flowchart.

My steps: I ran the code below to render a flowchart created through DiagrammeR. Reviewed and tried documentation and code at http://rich-iannone.github.io/DiagrammeR/graphviz_and_mermaid.html and https://yihui.org/tinytex/r/#debugging.

I am running RStudio 2021.09.01 on Window 10. It's a new laptop with recent R, RStudio, and tinytex installations. I have also tried Miktex installation with no pdf rendered.

I tried to create a new sample rmarkdown document that is able to render a pdf, but when the DiagrammeR code is added, no image is seen in the pdf, only the code. Rmarkdown is able to render a DiagrammeR flowchart in HTML. My backup is just to create an HTML and then convert to pdf:

knitr::opts_chunk$set(echo = TRUE)
tinytex::install_tinytex()
library(knitr)
library("tinytex")
library ("DiagrammeR")
library ("webshot")
library ("DiagrammeRsvg")
library ("rsvg")
library ("magrittr")

'''



'''
letters_greek = c("Α","Β","Γ","Δ","Ε","Ζ","Η","Ι","Κ","Λ","Μ","Ν","Ξ","Ο","Π","Ρ","Σ","Τ","Υ","Φ","Χ","Υ","Ω") 
graph <- grViz("
digraph graph_10_18 { 
# node definitions with substituted label text
node [fontname = Helvetica]
a [label = '@@1']
b [label = '@@2-1']
c [label = '@@2-2']
d [label = '@@2-3']
e [label = '@@2-4']
f [label = '@@2-5']
g [label = '@@2-6']
h [label = '@@2-7']
i [label = '@@2-8']
j [label = '@@2-9']
# edge definitions with the node IDs
a -> {b c d e f g h i j}
}
[1]: 'top'
[2]: letters_greek[1:10]
")
graph
DiagrammeRsvg::export_svg(graph) %>% charToRaw %>% rsvg::rsvg_pdf('graph.pdf')
'''


....but I still get the following error.


   > ****output file: Flowchart_actionable.knit.md

    >! LaTeX Error: Unicode character Α (U+0391)
               not set up for use with LaTeX.

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

    No LaTeX installation detected (LaTeX is required to create PDF output). 
    You should install a LaTeX distribution for your platform: 
    https://www.latex-project.org/get/
  
    If you are not sure, you may install TinyTeX in R: 
    tinytex::install_tinytex()
    Otherwise consider MiKTeX on Windows - http://miktex.org
    MacTeX on macOS - https://tug.org/mactex/
    (NOTE: Download with Safari rather than Chrome _strongly_ recommended)
    Linux: Use system package manager****
A V
  • 1
  • 2
  • As the error message suggests, have you run `tinytex::install_tinytex()`? – stefan Jan 24 '22 at 20:18
  • @stefan ```tinytex::install_tinytex()``` is in the second line of the code. That means it was ran. Thanks. Any other thoughts? – A V Jan 24 '22 at 20:29
  • Hm. Overlooked that. But anyway. I would try to run it from the console to install tinytex. Afterwards remove the line from your Rmd and try rendering a pdf. – stefan Jan 24 '22 at 20:35
  • Just as an update I renamed the grViz code as graph and added the following code: ```DiagrammeRsvg::export_svg(graph) %>% charToRaw %>% rsvg::rsvg_pdf('graph.pdf')``` and there was no rendering. – A V Jan 24 '22 at 20:42
  • I just tried to run your code but got an error ´LaTeX Error: Unicode character ...` which also shows up in the error message you posted. While I would still suggest to first run `install_tinytex` from the console one option which worked for me was to put the code to create the grViz in an R script, source it from within the Rmd and add the graph from the file using `![]("graph.pdf")`. – stefan Jan 24 '22 at 21:19

0 Answers0