Skip to contents

identify_blank_line_neighbors() identify and returns the indexes of blank lines around a specific line matching a pattern.

Usage

identify_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

library(readr)

file <- tempfile()

c("", "line 1", "", "", "line 2", "") |> write_lines(file)

x <- read_lines(file)

identify_blank_line_neighbors(x, pattern = "^line 2$")
#> [1] 4 6
#> [1] 4 6 # Expected