Newer
Older
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
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
31
32
33
34
35
36
37
38
39
40
\name{str_line_replace}
\alias{str_line_replace}
\alias{str_firstLine_replace}
\alias{str_lastLine_replace}
\title{Replace first or last line in strings}
\usage{
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{
\item{str}{String with pattern to make replacement}
\item{pattern}{Regular expression to replace}
\item{replacement}{What to replace the pattern with}
\item{which}{which one? first, last, all or the poles (first AND last)}
}
\value{
string
}
\description{
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()`.
}
\examples{
somelines <- c('AAAAA', 'textytext', 'BBBBB', \\n
'AAAAA', 'writingwriting', 'AAAAA', \\n
'etc', 'etc', 'BBBBB')
str_firstLine_replace(somelines, 'AAAAA', 'changedfirstline')
str_lastLine_replace(somelines, 'AAAAA', 'changedlastline')
str_line_replace(somelines, 'AAAAA', 'changedpoles', which='poles')
str_line_replace(somelines, 'AAAAA', 'changedall', which='all')
}
\seealso{
[stringr::str_replace()]
}