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