blank_line_neighbors()
identify and returns the indexes of blank lines
around a specific line matching a pattern.
blank_line_neighbors(
x,
pattern = NULL,
index = NULL,
top = TRUE,
bottom = TRUE
)
A character
vector.
A string indicating the pattern to look for. If there's more
than one match, the first one will be used (default: NULL
).
An integer number indicating the line to look for (default:
NULL
). If this parameter is provided, the pattern
parameter will be
ignored.
A logical
flag indicating if the function
should look for blank lines at the top of the line (default: TRUE
).
A logical
flag indicating if the
function should look for blank lines at the bottom of the line (default:
TRUE
).
An integer
vector with the indexes of the blank
lines.
file <- tempfile()
writeLines(c("", "line 1", "", "", "line 2", "", "", "line 3", ""), file)
x <- readLines(file)
blank_line_neighbors(x, pattern = "^line 2$")
#> [1] 4 6
#> [1] 4 6 # Expected