rich-iannone / DiagrammeR

Graph and network visualization using tabular data in R
https://rich-iannone.github.io/DiagrammeR/
Other
1.68k stars 247 forks source link

Integrate r variables in Mermaid Graph #483

Closed TazDP closed 7 months ago

TazDP commented 1 year ago

Hello,

I've been pulling my hair out for this:

Is it possible to include r variables in a mermaid graph? Something like

my_var <- 10

library(DiagrammeR)

my_var <- 10

mermaid("
graph LR
    A-->B
    B[%%%my_var%%%]
")

If not, shall I initiate a pull request?

Thanks a lot!

olivroy commented 8 months ago

You can always use other existing ways. DiagrammeR could possibly support that natively, but in the meantime, I can suggest using glue that uses { and } to deliminate R objects.


my_var <- 10

mermaid(glue::glue("
graph LR
    A-->B
    B[{my_var}]
"))

If you want to use %%% as delimiters, you can use

mermaid(glue::glue("
graph LR
    A-->B
    B[%%%my_var%%%]
",
.open = "%%%",
.close = "%%%"))