Description Usage Arguments Details Value Author(s) See Also Examples
Insert one or more lines
1 | sed_insert(stream, after, insertion, warn = FALSE, ...)
|
stream |
A character vector, each element typically (but not necessarily) containing the text
from a single line in a file, which can be generated via |
after |
An integer or character string that designates where |
insertion |
A character vector that will be inserted into the stream after element |
warn |
If |
... |
Additional named arguments to |
sed_insert only accomodates a single insertion point. Multiple lines may be inserted, but only one
insertion point is allowed, which is why length(insertion) must be 1. To make insertions at multiple locations,
sed_insert can be called repeatedly on the same string as needed.
The new stream with the insertions added. If the insertion fails because after is
specified incorrectly, stream is returned unchanged.
Landon Sego
sed_replace, sed_substitute, sed_comment, streamEdit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ################################################################################
# Let's create an example stream we can edit
################################################################################
stream <- c("Here's a line",
"And another line",
"Line after which we'll insert a string",
"A line after which we'll insert another string",
"A final line")
as.stream(stream)
# Insert a string using line numbers
stream <- sed_insert(stream, after = 3, "Here's the first insertion")
stream
# Insert a stream by searching for a string
stream <- sed_insert(stream,
c("Here's the second insertion",
"",
"Another line of the second insertion after the blank line"),
after = "insert another")
stream
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.