Identify blank lines around a line
Source:R/identify_blank_line_neighbors.R
identify_blank_line_neighbors.Rdidentify_blank_line_neighbors() identify and returns the indexes of blank
lines around a specific line matching a pattern.
Arguments
- x
A
charactervector.- 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, thepatternparameter will be ignored.- top
A
logicalflag indicating if the function should look for blank lines at the top of the line (default:TRUE).- bottom
A
logicalflag 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.
See also
Other file functions:
normalize_hashtags(),
normalize_names(),
peek_csv_file(),
remove_blank_line_dups(),
replace_in_file(),
sort_files_by_size(),
split_file(),
split_files_by_size(),
zip_files_by_pattern()
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