Learn R Programming

caugi (version 1.0.0)

write_caugi: Write caugi Graph to File

Description

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)

Value

Invisibly returns the input x.

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.

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

See Also

Other export: caugi_deserialize(), caugi_dot(), caugi_export(), caugi_graphml(), caugi_mermaid(), caugi_serialize(), export-classes, format-caugi, format-dot, format-graphml, format-mermaid, knit_print.caugi_export, read_caugi(), read_graphml(), to_dot(), to_graphml(), to_mermaid(), write_dot(), write_graphml(), write_mermaid()

Examples

Run this code
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))

# Clean up
unlink(tmp)

Run the code above in your browser using DataLab