Description Usage Arguments Details Value System requirements Examples
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.
1 2 |
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. |
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.
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.
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:
fontenc
xcolor
tikz
tikz-qtree
inconsolata
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.
1 | expr2tikz(y <- 2 * x, "fig.png")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.