Causal Graph Interface (for R) — a fast, tidy toolbox for building, coercing and analysing causal graphs.
caugi (pronounced “corgi”) wraps a high‑performance Rust core in a pipe‑friendly R interface. Convert between many graph formats, compose graphs with expressive infix operators, and run algorithms on large graphs. caugi aims to be the go‑to package for causal graphs in R.
Installation
You can install the development version of caugi from GitHub with:
# install.packages("pak")
pak::pak("frederikfabriciusbjerre/caugi")
# ... or wait for the first CRAN release
# install.packages("caugi")Example
The caugi syntax is very close to how you would draw a graph on a whiteboard. Here is a tiny DAG:
library(caugi)
cg <- caugi_graph(A %-->% B + C,
B %-->% D,
C %-->% D,
class = "DAG"
) # optional, guarantees acyclicity by construction
print(cg)
#> # A tibble: 4 × 1
#> name
#> <chr>
#> 1 A
#> 2 B
#> 3 C
#> 4 D
#> # A tibble: 4 × 3
#> from edge to
#> <chr> <chr> <chr>
#> 1 A --> B
#> 2 A --> C
#> 3 B --> D
#> 4 C --> DYou can query it:
neighbors(cg, "D")
#> [1] "B" "C"
parents(cg, "D")
#> [1] "B" "C"
children(cg, "A")
#> [1] "B" "C"
ancestors(cg, "D")
#> [1] "A" "B" "C"
descendants(cg, "A")
#> [1] "B" "C" "D"Key features
| 🚀 | What | Why it matters |
|---|---|---|
| Flexible coercion & formats |
as_caugi() ingests igraph, graphNEL, pcalg amat (CPDAG and PAG), and sparse or dense (binary/integer‑coded) matrices. |
Re‑use existing data structures; no tedious re‑encoding. |
| PAG & mixed‑graph support | Native edge codes for PAGs (o->, o-o, --o) and bidirected/undirected edges. |
Analyse outputs of discovery algorithms like FCI or RFCI out‑of‑the‑box. |
| Readable syntax |
A %-->% B, B %<->% C … |
Write graphs exactly as you draw them on a whiteboard. |
| Blazing speed | Core implemented in Rust in a Compressed Sparse Row (CSR) representation. | Millions of edges? No problem. |
| Frontloading computation | The CSR format is build to be immutable by design. You can add edges/nodes, but the graph is only rebuilt when you call build() or query the graph. |
Avoids unnecessary recomputation; keeps your code snappy (and keeps you happy). |
| S7 | Modern S7 classes and methods. Made to be hard to break by mistake. | Future‑proof, safe, and extensible. |