View source: R/30-api-flexseq-ends.R
| insert_at | R Documentation |
Inserts values before the current element at index.
insert_at(x, index, values)
x |
A |
index |
One-based insertion position in |
values |
Values to insert. |
values is interpreted as a collection of elements to splice in.
Common cases:
Atomic vector (c("x", "y")): inserts one element per vector entry.
List (list("x", "y")): inserts one element per list entry.
flexseq: inserts all of its elements.
Empty input (list() or flexseq()): no change.
To insert one composite object (for example, a vector or a list) as a single
element, wrap it in list(...).
This operation is persistent: x is not modified.
Updated sequence with inserted values.
x <- flexseq("a", "b", "c", "d")
insert_at(x, 3, c("x", "y"))
insert_at(x, 1, "start")
insert_at(x, length(x) + 1, "end")
# Insert one vector as a single element
insert_at(x, 3, list(c("u", "v")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.