These functions download the diagram from https://mermaid.ink which generates the image.
mermaid(
diagram,
format = "png",
theme = "default",
dir.dest = tempdir(),
file.dest = paste0(rlang::hash(link), ".", format),
server = Sys.getenv("MERMAID_URL", "https://mermaid.ink"),
link = mermaid_gen_link(diagram, theme = theme, format = format, server = server)
)
mermaid_gen_link(
diagram,
theme = "default",
format = "png",
server = Sys.getenv("MERMAID_URL", "https://mermaid.ink")
)
# S3 method for class 'mermaid'
plot(x, add = FALSE, ...)
Diagram in mermaid markdown-like language or file (as a connection or file name) containing a diagram specification
Image format (either "jpg"
, or "png"
, or "svg"
)
Mermaid theme (See available themes in Mermaid documentation)
Destination folder for the downloaded image. This parameter is
ignored if file.dest
contains a folder path.
Path to the downloaded image. It's combined with dir.dest
if it only contains the name of the file without a folder path.
URL of the server used to generate the link
Link generated by mermaid_gen_link
character mermaid diagram dialect
logical to add the diagram on the existing plot
Other argument passed to mermaid
mermaid
returns the path to the downloaded image or NA
if the download failed.
In this latter case, get the error message in the attribute "error".
mermaid_gen_link
returns the link to the web service which generates the diagram
plot.mermaid
produces a R plot with the mermaid diagram
Nothing, used for side effect.
Compared to the diagrammeR::mermaid
function, the generated image or plot
is not a HTMLwidget and can be knit in pdf through latex and
moreover, its size can be controlled with fig.width
and fig.height
.
If the generation failed (due to internet connection failure or syntax error
in mermaid script), the functions raises no error (see mermaid
returned value).
By default, mermaid
uses the service https://mermaid.ink.
One can define an alternative server to use with the environment variable
MERMAID_URL
.
diagram <- "flowchart LR\n A --> B"
mermaid_gen_link(diagram)
#> [1] "https://mermaid.ink/img/pako:eNqrVkrOT0lVslJKy8kvT85ILCpR8AmKyVNQcFTQ1bVTcFLSUcpNLcpNzExRsqpWKslIzQUpTklNSyzNKVGqrQUAjIcUfg?type=png"
# \dontrun{
f <- mermaid(diagram)
#> Warning: URL 'https://mermaid.ink/img/pako:eNqrVkrOT0lVslJKy8kvT85ILCpR8AmKyVNQcFTQ1bVTcFLSUcpNLcpNzExRsqpWKslIzQUpTklNSyzNKVGqrQUAjIcUfg?type=png': Timeout of 60 seconds was reached
f
#> [1] NA
#> attr(,"error")
#> [1] "cannot open URL 'https://mermaid.ink/img/pako:eNqrVkrOT0lVslJKy8kvT85ILCpR8AmKyVNQcFTQ1bVTcFLSUcpNLcpNzExRsqpWKslIzQUpTklNSyzNKVGqrQUAjIcUfg?type=png'"
# For displaying the diagram in Rmarkdown document
knitr::include_graphics(mermaid(diagram))
#> Warning: URL 'https://mermaid.ink/img/pako:eNqrVkrOT0lVslJKy8kvT85ILCpR8AmKyVNQcFTQ1bVTcFLSUcpNLcpNzExRsqpWKslIzQUpTklNSyzNKVGqrQUAjIcUfg?type=png': Timeout of 60 seconds was reached
#> Error in Encoding(x): a character vector argument expected
# Clean temporary folder
unlink(f)
# }
# \dontrun{
s <- "flowchart LR
A --> B"
class(s) <- c("mermaid", class(s))
plot(s)
#> Warning: URL 'https://mermaid.ink/img/pako:eNqrVkrOT0lVslJKy8kvT85ILCpR8AmKyXNU0NW1U3BS0lHKTS3KTcxMUbKqVirJSM0FKU1JTUsszSlRqq0FAHJVFD4?type=png': Timeout of 60 seconds was reached
#> Warning: Mermaid diagram generation failed with error:
#> cannot open URL 'https://mermaid.ink/img/pako:eNqrVkrOT0lVslJKy8kvT85ILCpR8AmKyXNU0NW1U3BS0lHKTS3KTcxMUbKqVirJSM0FKU1JTUsszSlRqq0FAHJVFD4?type=png'
# }