Learn R Programming

automerge (version 0.3.0)

am_clone: Clone an Automerge document

Description

Creates an independent deep copy of an Automerge document, preserving the same actor ID. Changes to the clone do not affect the original, and vice versa.

Usage

am_clone(doc)

Value

A new Automerge document (independent copy with same actor ID)

Arguments

doc

An Automerge document

Details

Unlike am_fork(), which assigns a new actor ID to the copy, am_clone() preserves the original actor ID. This makes it suitable for archival snapshots or checkpoints where you want an exact copy of the document state. Do not use am_clone() to create branches that will make independent edits and later be merged — use am_fork() for that, as two documents sharing an actor ID can cause conflicts.

See Also

am_fork() for creating branches with a new actor ID

Examples

Run this code
doc <- am_create()
doc$key <- "value"
am_commit(doc)

clone <- am_clone(doc)
clone$key  # "value"

# Clone preserves the actor ID
am_get_actor_hex(doc) == am_get_actor_hex(clone) # TRUE

# Changes to clone don't affect original
clone$key <- "changed"
doc$key  # still "value"

am_close(doc)
am_close(clone)

Run the code above in your browser using DataLab