Skip to contents

You can use nomnoml chunks in R Markdown with HTML output. Here is an example R Markdown, including the yaml header. Notice that you can use nomnoml chunks and these will be rendered by the nomnoml engine.

---
title: "A Diagram"
output: html_document
---

```{r, setup, include=FALSE}
library(nomnoml)
```

```{nomnoml}
#stroke: orange
#.box: fill=#8f8 dashed visual=ellipse

[A]-[B]-[<box>C]
```

Chunk examples

Here is a rendered example of a chunk, using the default plot size:

#stroke: #a86128
#direction: down
[<frame>Decorator pattern|
  [<abstract>Component||+ operation()]
  [Client] depends --> [Component]
  [Decorator|- next: Component]
  [Decorator] decorates -- [ConcreteComponent]
  [Component] <:- [Decorator]
  [Component] <:- [ConcreteComponent]
]

And the same diagram, this time with specified size:

#stroke: #a86128
#direction: down
[<frame>Decorator pattern|
  [<abstract>Component||+ operation()]
  [Client] depends --> [Component]
  [Decorator|- next: Component]
  [Decorator] decorates -- [ConcreteComponent]
  [Component] <:- [Decorator]
  [Component] <:- [ConcreteComponent]
]

Unicode chunks

Unicode escapes (using R conventions) can be used in code chunks.

In the next example, the unicode character \u03b1 displays as greek alpha (α).

```{nomnoml, escape = TRUE}
[Hello]-\u03B1[Unicode!]
```

Of course, you can use the unicode character directly

```{nomnoml, escape = TRUE}
[Hello]-α[Unicode!]
```

To include backslashes in labels, specify escape = TRUE:

```{nomnoml, escape = TRUE}
[Hello]-\A[Escape character!]
```

Multiple nodes per line

During 2023 the nomnoml.js library added support for multiple nodes in a single line. The R package incorporates these changes since version 0.3.0.

This means it’s possible to create diagrams like this:

#direction: right
[<start>start] -> [process] -> [<end>end]