[Experimental]

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
)

Arguments

x

A character vector.

pattern

A string indicating the pattern to look for. If there's more than one match, the first one will be used (default: NULL).

index

An integer number indicating the line to look for (default: NULL). If this parameter is provided, the pattern parameter will be ignored.

top

A logical flag indicating if the function should look for blank lines at the top of the line (default: TRUE).

bottom

A logical flag indicating if the function should look for blank lines at the bottom of the line (default: TRUE).

Value

An integer vector with the indexes of the blank lines.

Examples

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