doc <- am_create()
am_put(doc, AM_ROOT, "doc", am_text("Hello"))
text_obj <- am_get(doc, AM_ROOT, "doc")
text_obj
# Insert " World" at position 5 (after "Hello")
am_text_splice(text_obj, 5, 0, " World")
# Get the full text
am_text_content(text_obj) # "Hello World"
# Works naturally with multibyte characters
am_put(doc, AM_ROOT, "greet", am_text(""))
text_obj2 <- am_get(doc, AM_ROOT, "greet")
am_text_splice(text_obj2, 0, 0, "Column café")
# Position 11 is after "café" (character index, not bytes)
am_text_splice(text_obj2, 11, 0, "!")
am_text_content(text_obj2) # "Column café!"
am_close(doc)
Run the code above in your browser using DataLab