flow_view: View function as flow chart

View source: R/03_0_flow_view.R

flow_viewR Documentation

View function as flow chart

Description

  • flow_view() shows the code of a function as a flow diagram

  • flow_run() runs a call and draws the logical path taken by the code.

  • flow_compare_runs() shows on the same diagrams 2 calls to the same functions, code blocks that are only touched by the ref call are colored green, code blocks that are only touched by the x call are colored orange.

Usage

flow_view(
  x,
  prefix = NULL,
  code = TRUE,
  narrow = FALSE,
  truncate = NULL,
  nested_fun = NULL,
  swap = TRUE,
  out = NULL,
  engine = c("nomnoml", "plantuml")
)

flow_run(
  x,
  prefix = NULL,
  code = TRUE,
  narrow = FALSE,
  truncate = NULL,
  swap = TRUE,
  out = NULL,
  browse = FALSE
)

flow_compare_runs(
  x,
  ref,
  prefix = NULL,
  code = TRUE,
  narrow = FALSE,
  truncate = NULL,
  swap = TRUE,
  out = NULL
)

Arguments

x

a call, a function, or a path to a script

prefix

prefix to use for special comments in our code used as block headers, must start with "#", several prefixes can be provided

code

Whether to display the code in code blocks or only the header, to be more compact, if NA, the code will be displayed only if no header is defined by special comments

narrow

TRUE makes sure the diagram stays centered on one column (they'll be longer but won't shift to the right)

truncate

maximum number of characters to be printed per line

nested_fun

if not NULL, the index or name of the function definition found in x that we wish to inspect

swap

whether to change var <- if(cond) expr into if(cond) var <- expr so the diagram displays better

out

a path to save the diagram to. Special values "html", "htm", "png", "pdf", "jpg" and "jpeg" can be used to export the object to a temp file of the relevant format and open it, if a regular path is used the format will be guessed from the extension.

engine

either "nomnoml" (default) or "plantuml" (experimental, brittle mostly for reasons out of our control), if the latter, arguments prefix, narrow, and code are ignored

browse

whether to debug step by step (block by block), can also be a vector of block ids, in this case browser() calls will be inserted at the start of these blocks

ref

the reference expression for flow_compare_runs()

Details

On some systems the output might sometimes display the box character when using the nomnoml engine, this is due to the system not recognizing the Braille character ⁠\u2800⁠. This character is used to circumvent a shortcoming of the nomnoml library: lines can't start with a standard space and multiple subsequent spaces might be collapsed. To choose another character, set the option flow.indenter, for instance : options(flow.indenter = "\u00b7"). Setting the options(flow.svg = FALSE) might also help.

Value

depending on out :

  • NULL (default) : flow_view() and flow_compare_runs() return a "flow_diagram" object, containing the diagram, the diagram's code and the data used to build the code. flow_run() returns the output of the call.

  • An output path or a file extension : the path where the file is saved

  • "data": a list of 2 data frames "nodes" and "edges"

  • "code": A character vector of class "flow_code"

Examples

flow_view(rle)
flow_run(rle(c(1, 2, 2, 3)))
flow_compare_runs(rle(NULL), rle(c(1, 2, 2, 3)))

flow documentation built on June 7, 2023, 5:17 p.m.