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),
link = mermaid_gen_link(diagram, theme = theme, format = format)
)
mermaid_gen_link(
diagram,
theme = "default",
format = "png",
server = "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.
Link generated by mermaid_gen_link
URL of the server used to generate the 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).
# \dontrun{
diagram <- "flowchart LR\n A --> B"
mermaid_gen_link(diagram)
#> [1] "https://mermaid.ink/img/pako:eNqrVkrOT0lVslJKy8kvT85ILCpR8AmKyVNQcFTQ1bVTcFLSUcpNLcpNzExRsqpWKslIzQUpTklNSyzNKVGqrQUAjIcUfg?type=png"
f <- mermaid(diagram)
f
#> [1] "/tmp/RtmpkcMnIA/a0a48ce294b1a6f989506ce145809601.png"
# For displaying the diagram in Rmarkdown document
knitr::include_graphics(mermaid(diagram))
#> [1] "/tmp/RtmpkcMnIA/a0a48ce294b1a6f989506ce145809601.png"
#> attr(,"class")
#> [1] "knit_image_paths" "knit_asis"
# Clean temporary folder
unlink(f)
# }
s <- "flowchart LR
A -> B"
class(s) <- c("mermaid", class(s))
plot(s)
#> Warning: downloaded length 0 != reported length 20
#> Warning: cannot open URL 'https://mermaid.ink/img/pako:eNqrVkrOT0lVslJKy8kvT85ILCpR8AmKyXNU0LVTcFLSUcpNLcpNzExRsqpWKslIzQWpTElNSyzNKVGqrQUAY2oUEQ?type=png': HTTP status was '400 Bad Request'
#> Warning: Mermaid diagram generation failed with error:
#> cannot open URL 'https://mermaid.ink/img/pako:eNqrVkrOT0lVslJKy8kvT85ILCpR8AmKyXNU0LVTcFLSUcpNLcpNzExRsqpWKslIzQWpTElNSyzNKVGqrQUAY2oUEQ?type=png'