Description Usage Arguments Value Author(s) See Also Examples
Delete or replace an entire line
1 | sed_replace(stream, at, replacement, 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 |
at |
A vector of integers or a character string that designates where |
replacement |
A character string of length 1 (vectors not supported), that will be inserted
to replace the entire line. Or, if |
warn |
If |
... |
Additional named arguments to |
The new stream
with the replacements. If the replacement fails because after
is
specified incorrectly, stream
is returned unchanged.
Landon Sego
sed_insert
, 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 22 23 24 25 26 27 28 29 30 | ################################################################################
# Let's create an example stream we can edit
################################################################################
stream <- c("Here's a line",
"Here's a line we'll delete",
"Filler line",
"A line we'll delete",
"A line we'll entirely replace",
"The last line")
as.stream(stream)
# Here's a deletion of lines 1 and 2 using line numbers
stream <- sed_replace(stream, 1:2, NULL)
stream
# Here's a line deletion using a search string
stream <- sed_replace(stream, "A line we'll delete", NULL)
stream
# A line replacement using line numbers
stream <- sed_replace(stream, 2, "A new filler line")
stream
# Here's a line replacement with a search string
stream <- sed_replace(stream, "entirely", "A replacement for the line")
stream
# And we can replace multiple lines too
stream <- sed_replace(stream, "line", "All the same")
stream
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.