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(),
split_file()
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