Skip to contents

Writes a caugi graph to a file in the native caugi JSON format. This format is designed for reproducibility, caching, and sharing caugi graphs across R sessions.

Usage

write_caugi(x, path, comment = NULL, tags = NULL)

Arguments

x

A caugi object or an object coercible to caugi.

path

Character string specifying the file path.

comment

Optional character string with a comment about the graph.

tags

Optional character vector of tags for categorizing the graph.

Value

Invisibly returns the input x.

Details

The caugi format is a versioned JSON schema that captures:

  • Graph structure (nodes and edges with their types)

  • Graph class (DAG, PDAG, ADMG, UG, etc.)

  • Optional metadata (comments and tags)

Edge types are encoded using their DSL operators (e.g., "-->", "<->", "--").

For a complete guide to the format, see vignette("serialization", package = "caugi"). The formal JSON Schema is available at: https://caugi.org/schemas/caugi-v1.schema.json

Examples

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

# Write to file
tmp <- tempfile(fileext = ".caugi.json")
write_caugi(cg, tmp, comment = "Example DAG")

# Read back
cg2 <- read_caugi(tmp)
identical(edges(cg), edges(cg2))
#> [1] TRUE

# Clean up
unlink(tmp)