expr2tikz: Translate R expression into tikz-qtree and save figure

Description Usage Arguments Details Value System requirements Examples

Description

Plots the abstract syntax tree of an expression in a pdf, png, or svg file. The qtree string assumes the node styles call, sym, and lit to exist (call, symbol, and literal nodes, respectively). See below for system requirements.

Usage

1
2
expr2tikz(expr, filename = NULL, path = NULL, dpi = 600,
  keep_tex = FALSE)

Arguments

expr

expression

NB: the current version can't handle named arguments, neither in function calls nor definitions.

filename

file name with extension (either .png, .svg, or .pdf) or NULL for not saving an output file.

path

directory in which to save the figure (NULL for current working directory)

dpi

image density, only relevant for png output

keep_tex

should the .tex file be saved as well?

This argument is ignored if filename is NULL.

Details

This function is heavily inspired by the abstract syntax tree figures in Hadley Wickham's Advanced R, Section 20 (Expressions), and the tikz styles are made to closely mimic the style of those figures. The code itself is adapted from the function ast.

Value

qtree string, invisibly. If a filename was provided, it will have node styles, otherwise it will be as plain as possible and printed to the console.

System requirements

In order to render the tree, the following components are required to be installed on the system:

For pdf figures, pdflatex must be installed (e.g. with TeXLive or MiKTeX) and on the PATH, and the following packages must be installed:

For png figures, the requirements for pdf figures must be met, and in addition, convert from the ImageMagick suite must be installed and on the PATH.

For svg figures, the requirements for pdf figures must be met, and in addition, pdf2svg must be installed and on the PATH.

Examples

1
expr2tikz(y <- 2 * x, "fig.png")

janusvm/jsvm documentation built on May 28, 2019, 9:39 a.m.