Description Usage Arguments Value Author(s) See Also Examples
View source: R/sed_substitute.R
Substitute one string for another
1 2 | sed_substitute(stream, pattern, replacement, every = TRUE, 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 |
pattern |
A character string containing the regular expression that will be used to identify
which the elements (or lines) in |
replacement |
A character string (vectors not supported), that will be substituted
for the |
every |
A logical indicating whether every instance of |
warn |
If |
... |
Additional named arguments to |
The new stream
with the substitions. If the substitution fails because pattern
is not found,
stream
is returned unchanged.
Landon Sego
sed_insert
, sed_replace
, 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 | ################################################################################
# Let's create an example stream we can edit
################################################################################
stream <- c("Here's a line",
"A line where we'll make a substitution",
"A line where we'll delete 'this'",
"Several nonsense nonsense repeated strings nonsense",
"Another nonsense line with nonsense repeated strings",
"The last line")
as.stream(stream)
# Here's a deletion within the line
stream <- sed_substitute(stream, " 'this'", "")
stream
# Here's a substitution of text
stream <- sed_substitute(stream, "substitution", "correction")
stream
# Show the difference between 'every = TRUE' and 'every = FALSE'
sed_substitute(stream, " nonsense", "", every = TRUE)
sed_substitute(stream, " nonsense", "", every = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.