Learn R Programming

automerge (version 0.3.0)

am_get_path: Navigate deep structures with path

Description

Get a value from an Automerge document using a path vector. The path can contain character keys (for maps), numeric indices (for lists, 1-based), or a mix of both.

Usage

am_get_path(doc, path)

Value

The value at the path, or NULL if not found

Arguments

doc

An Automerge document

path

Character vector, numeric vector, or list of mixed types specifying the path to navigate

Examples

Run this code
doc <- am_create()
am_put(doc, AM_ROOT, "user", list(
  name = "Alice",
  address = list(city = "NYC", zip = 10001L)
))

# Navigate to nested value
am_get_path(doc, c("user", "address", "city"))  # "NYC"

# Mixed navigation (map key, then list index)
doc$users <- list(
  list(name = "Bob"),
  list(name = "Carol")
)
am_get_path(doc, list("users", 1, "name"))  # "Bob"

am_close(doc)

Run the code above in your browser using DataLab