Learn R Programming

caugi

Causal Graph Interface (for R) — a fast and flexible toolbox for building, coercing and analyzing causal graphs.

What is caugi?

caugi (pronounced “corgi”) stands for Causal Graph Interface. It is a causality-first graph package that focuses on performance and flexibility. If you are developing scripts or algorithms in the field of causality or if you are learning about causal graphs for the first time, caugi is made for you.

Installation

You can install the development version of caugi from GitHub with:

pak::pak("frederikfabriciusbjerre/caugi")

or directly from CRAN with:

install.packages("caugi")

Installing Rust

Rust is required for caugi to work. If you don’t have Rust installed, visit rustup.rs for installation instructions appropriate for your platform.

Alternatively, you may install Rust from your OS package manager.

The basic object: caugi

A caugi graph object is the bread and butter of the caugi package. It is easy to create, query, and modify.

library(caugi)

You can create simple graphs as well as a number of predefined graph classes. Currently, we support "UNKNOWN", "DAG", "PDAG", "ADMG", and "UG". We plan on supporting several other causal graph types in future releases, such as "PAG", "MAG", and "SWIG".

# a tiny DAG
cg <- caugi(
  A %-->% B + C,
  B %-->% D,
  C %-->% D,
  class = "DAG"
)

plot(cg)

Edge operators

The available edges in caugi are listed below:

  • %-->% (directed)
  • %---% (undirected)
  • %<->% (bidirected)
  • %o->% (partially directed)
  • %o--% (partially undirected)
  • %o-o% (partial)

You can register more types with register_caugi_edge(), if you find that you need a more expressive set of edges. For example, if you want to represent a directed edge in the reverse direction, you can do so like this:

register_caugi_edge(
  glyph = "<--",
  tail_mark = "arrow",
  head_mark = "tail",
  class = "directed",
  symmetric = FALSE
)

caugi(A %-->% B, B %<--% C, class = "DAG")
#> <caugi object; 3 nodes, 2 edges; simple: TRUE; built: TRUE; ptr=0x562aff8da3a0>
#>   graph_class: DAG
#>   nodes: A, B, C
#>   edges: A-->B, B<--C

# reset the registry to default with original edges
reset_caugi_registry()

We expect this feature to be needing further polishing in future releases, and we would love your input if you use this feature!

Querying and metrics

caugi provides a number of functions to query and analyze caugi objects. Some of the available functions are:

  • Relational queries, such as parents(), ancestors(), neighbors(), and more.
  • Structural queries, such as is_acyclic(), is_cpdag(), and more.
  • Graph manipulations, such as add_edge(), remove_node(), and more.
  • Graph metrics, such as shd() and aid().

How it works

caugi graphs are represented in a compact Compressed Sparse Row (CSR) format in Rust. caugi works with a front-loading philosophy. Since the caugi graph is stored in a CSR format, mutations of the graph is computationally expensive compared to other graph storage systems, but it allows for very fast querying. Additionally to the storage format of the graph itself, caugi also stores additional information about node relations in such a way that it allows for faster queries without blowing up the object too much.

To accommodate for the cost of mutations, caugi graphs are built lazily. This means that when you mutate the graph, for example by adding edges to it, the graph edits are stored in R, but not in Rust. When you then need to query the graphs, the graph will rebuild itself in Rust, and the query will be executed on the newly built graph. You can also use the build(cg) function to force building the graph in Rust at any time.

Why?

It’s fast, dawg

Copy Link

Version

Install

install.packages('caugi')

Version

1.0.0

License

MIT + file LICENSE

Maintainer

Frederik Fabricius-Bjerre

Last Published

January 22nd, 2026

Functions in caugi (1.0.0)

caugi_layout

Compute Graph Layout
caugi_plot

S7 Class for caugi Plot
caugi_layout_bipartite

Bipartite Graph Layout
caugi_verbs

Manipulate nodes and edges of a caugi
children

Get children of nodes in a caugi
caugi_serialize

Serialize caugi Graph to JSON String
.expand_nodes

Expand node expressions
caugi_mermaid

S7 Class for Mermaid Export
caugi_options

Get or set global options for caugi
caugi_layout_tiered

Tiered Graph Layout
districts

Get districts (c-components) of an ADMG
caugi_layout_sugiyama

Sugiyama Hierarchical Layout
descendants

Get descendants of nodes in a caugi
caugi_dot

S7 Class for DOT Export
.edge_constructor

Edge constructor
.collect_edges_nodes

Collect edges and nodes
.cg_state

Create the state environment for a caugi (internal)
.expand_targets

Helper to expand the right-hand side of an edge specification
.edge_constructor_idx

Edge constructor using indices.
caugi_layout_fruchterman_reingold

Fruchterman-Reingold Force-Directed Layout
.getter_output

Output object of getter queries
.get_nodes

Get nodes data.table from verb call.
divide-caugi_plot-caugi_plot

Compose Plots Vertically
.edge_ops_get

Get edge operators
.glyph_of

Get glyph for an operator
caugi_layout_kamada_kawai

Kamada-Kawai Stress Minimization Layout
condition_marginalize

Marginalize and/or condition on variables in an ancestral graph (AG)
.view_to_caugi

Convert a graph pointer to a caugi S7 object
.glyph_map_get

Get edge operators
d_separated

Are X and Y d-separated given Z?
.is_edge_call

Is it an edge call / expression?
.edge_type_from_anteriors

Infer edge type from anterior relationships
.edge_units_to_dt

Turn edge units into a data.table of edges
exogenize

Exogenize a graph
edge_operators

Infix operators for edge specifications
.is_node_expr

Is it a node expr?
.edge_spec

Edge specification infix operators
edges

Get edges of a caugi.
.caugi_fit_on_line

Fit items on a line
edge_types

Get the edge types of a caugi.
.register_edge

Register a new edge operator
.contains_edge

Does the expression contain an edge call?
.combine_plus

Combine terms with '+'
exogenous

Get all exogenous nodes in a caugi
makeContent.caugi_edge_grob

Make Content for Custom Edge Grob
.node_constructor

Node constructor
.mark_not_built

Mark a caugi as not built.
.segment_units

Create an edge unit from lhs, op, rhs
.flatten_edge_chain

Flatten a chained edge expression
.split_plus

Expand target expressions with =
.get_edges

Build edges data.table from verb call.
is_empty_caugi

Is the caugi graph empty?
.resolve_idx0_get

Resolve node name or index to 0-based index.
format-dot

DOT Format Export and Import
format-graphml

GraphML Format Export and Import
is_dag

Is the caugi graph a DAG?
register_caugi_edge

Register a new edge type in the global registry.
is_edge_symmetric

Is the edge symmetric?
read_graphml

Read GraphML File to caugi Graph
is_mag

Is the caugi graph a MAG?
is_pdag

Is the caugi graph a PDAG?
is_ug

Is the caugi graph an UG?
to_mermaid

Export caugi Graph to Mermaid Format
to_graphml

Export caugi Graph to GraphML Format
.parse_edge_arg

Parse one caugi(...) argument
.set_names

Set names to an object
.not_m_separated_for_all_subsets

Check if nodes are NOT m-separated for all conditioning subsets
format-mermaid

Mermaid Format Export
generate_graph

Generate a caugi using Erdős-Rényi.
.update_caugi

Update nodes and edges of a caugi
markov_blanket

Get Markov blanket of nodes in a caugi
hd

Hamming Distance
is_acyclic

Is the caugi acyclic?
is_admg

Is the caugi graph an ADMG?
is_ag

Is the caugi graph an AG?
is_valid_adjustment_admg

Is a set a valid adjustment set in an ADMG?
length

Length of a caugi
moralize

Moralize a DAG
m_separated

M-separation test for AGs and ADMGs
mutate_caugi

Mutate caugi class
topological_sort

Get a topological ordering of a DAG
write_caugi

Write caugi Graph to File
export-classes

Export Format Classes
format-caugi

Caugi Native Format Serialization
knit_print.caugi_export

Knit Print Method for caugi_export
is_caugi

Is it a caugi graph?
is_cpdag

Is the caugi graph a CPDAG?
write_mermaid

Write caugi Graph to Mermaid File
is_valid_backdoor

Is a backdoor set valid?
shd

Structural Hamming Distance
read_caugi

Read caugi Graph from File
subgraph

Get the induced subgraph
to_dot

Export caugi Graph to DOT Format
print

Print a caugi
simulate_data

Simulate data from a caugi DAG.
latent_project

Project latent variables from a DAG to an ADMG
parents

Get parents of nodes in a caugi
skeleton

Get the skeleton of a graph
plot

Create a caugi Graph Plot Object
spouses

Get spouses (bidirected neighbors) of nodes in an ADMG
same_nodes

Same nodes?
nodes

Get nodes or edges of a caugi
neighbors

Get neighbors of nodes in a caugi
registry

caugi edge registry
write_dot

Write caugi Graph to DOT File
write_graphml

Write caugi Graph to GraphML File
ancestors

Get ancestors of nodes in a caugi
as_adjacency

Convert a caugi to an adjacency matrix
all_backdoor_sets

Get all backdoor sets up to a certain size.
anteriors

Get anteriors of nodes in a caugi
add-caugi_plot-caugi_plot

Compose Plots Horizontally
aid

Adjustment Identification Distance
all_adjustment_sets_admg

Get all valid adjustment sets in an ADMG
as_caugi

Convert to a caugi
adjustment_set

Compute an adjustment set
as_bnlearn

Convert a caugi to a bnlearn network
caugi

Create a caugi from edge expressions.
caugi_deserialize

Deserialize caugi Graph from JSON String
as_igraph

Convert a caugi to an igraph object
caugi_export

S7 Base Class for Caugi Exports
build

Build the graph now
as_dagitty

Convert a caugi to a dagitty graph
caugi_default_options

Default options for caugi
caugi_graphml

S7 Class for GraphML Export
caugi-package

caugi (Causal Graph Interface)