Learn R Programming

qreport (version 1.1-0)

makedot: Create a General Quarto Graphviz Flow Diagram from Plain Text With Variable Insertions

Description

Takes a character string or vector and creates a graphviz dot flowchart from the input. There are two kinds of input strings or lines. One defines nodes, the syntax being nodename:string where nodename is any valid graphviz node name and string represents a character string with possible variable value substitutions of the form {{variablename}}. string is automatically wrapped by having newline characters inserted to keep lines within width characters. The second kind of input line is one specifying node connections with graphviz dot syntax, respecting node names defined in earlier strings. Unlike makegvflow(), this approach allows a node to connect to any number of other nodes, and allows any flow direction.

Usage

makedot(
  .object.,
  ...,
  direction = c("TD", "LR"),
  shape = "box",
  fontsize = 24,
  nodesetup = NULL,
  file,
  width = 30,
  onlyprint = FALSE
)

Value

nothing; used to knitr::knit_expand() graphviz markup

Arguments

.object.

character string or vector of plain text plus possible $LaTeX$ math delimited by single dollar signs. An empty initial line is ignore, so the user need not worry about having an initial quote mark on a line by itself.

...

name=value pairs that makes values replace {{name}} elements in the markup

direction

direction of the flow chart, default is top-down

shape

node shape

fontsize

text font size

nodesetup

extra node setup to include after direction

file

name of file to hold graphviz markup after variable insertions. Run this in Quarto using a chunk to looks like what is below, which was for file='graphviz.dot'.

width

text width for word-wrapping

onlyprint

set to TRUE to only print the generated graphiz markup and not save it to file

```{dot}
//| label: fig-flow1
//| fig-height: 4
//| fig-cap: "Chart caption"
//| file: graphviz.dot
```

Author

Frank Harrell

Details

If a node label contains \\n, all \\n are replaced with \n and ordinary word wrapping is suppressed. This is how users take control of line splitting. If a node label ends in //any text, the text in any text will be copied to inside the node definition after the label is closed with double quote and after a space is added. This allows node colors and other attributes to be changed.

Preceed single quotes in node labels with a single backslash. Preceed double quotes with double backslashes.

The function uses knitr::knit_expand() to apply variable insertions before the diagram is rendered by Quarto. See this for an example. ##' @title makedot

See Also

makegraphviz(), makegvflow()

Examples

Run this code
x <- '
A:Some string of text for {{jj}}
B:Another string of test, this one being longer and needing breaking
C:A third string defining a node//style="filled,rounded", fillcolor=lightblue
A -> B
B -> C [label="some text along connecting arc"]
C -> A'
# Can also use A -> {B, C}
makedot(x, jj='tiger', onlyprint=TRUE)

Run the code above in your browser using DataLab