Learn R Programming

automerge (version 0.3.1)

am_insert: Insert a value into an Automerge list

Description

This is an alias for am_put() with insert semantics for lists. For lists, am_put() with a numeric index replaces the element at that index, while am_insert() shifts elements to make room.

Usage

am_insert(doc, obj, pos, value)

Value

The document doc (invisibly)

Arguments

doc

An Automerge document

obj

An Automerge object ID (must be a list)

pos

Numeric index (1-based, like R vectors) where to insert, or "end" to append

value

The value to store. Supported types:

  • NULL - stores null

  • Logical - stores boolean (must be scalar)

  • Integer - stores integer (must be scalar)

  • Numeric - stores double (must be scalar)

  • Character - stores string (must be scalar)

  • Raw - stores bytes

  • AM_OBJ_TYPE_LIST/MAP/TEXT - creates nested object

Examples

Run this code
doc <- am_create()

# Create a list and get it
am_put(doc, AM_ROOT, "items", AM_OBJ_TYPE_LIST)
items <- am_get(doc, AM_ROOT, "items")
items

# Insert items
am_insert(doc, items, "end", "first")
am_insert(doc, items, "end", "second")

am_close(doc)

Run the code above in your browser using DataLab