Learn R Programming

automerge (version 0.3.0)

am_load_changes: Load a document as individual changes

Description

Decomposes a serialized document into its individual changes. This is useful for inspecting the full change history or for selectively applying changes to another document.

Usage

am_load_changes(data)

Value

A list of am_change objects. Returns an empty list for an empty document.

Arguments

data

A raw vector containing a serialized Automerge document (from am_save())

Examples

Run this code
doc <- am_create()
doc$key <- "value"
am_commit(doc, "Add key")
doc$key2 <- "value2"
am_commit(doc, "Add key2")
bytes <- am_save(doc)

# Load as individual changes
changes <- am_load_changes(bytes)
length(changes)  # 2
am_change_message(changes[[1]])  # "Add key"
am_change_message(changes[[2]])  # "Add key2"

# Apply to a new document
doc2 <- am_create()
am_apply_changes(doc2, changes)
doc2$key   # "value"
doc2$key2  # "value2"

am_close(doc)
am_close(doc2)

Run the code above in your browser using DataLab