These functions serve to change the first or last line of strings which match a specific pattern (regex). `str_firstLine_replace()` replaces the first line that matches the pattern. `str_lastLine_replace()` replaces the last line that matches the pattern They are useful, for example, when reading a text file with many lines and you want to preserve the lines of that text file. When `which='all'`, it is a wrapper for `stringr::str_replace()`.

str_line_replace(
  str,
  pattern,
  replacement,
  which = c("first", "last", "poles", "all")
)

str_firstLine_replace(str, pattern, replacement)

str_lastLine_replace(str, pattern, replacement)

Arguments

str

String with pattern to make replacement

pattern

Regular expression to replace

replacement

What to replace the pattern with

which

which one? first, last, all or the poles (first AND last)

Value

string

See also

[stringr::str_replace()]

Examples