Remove blank line duplicates from a file
Source:R/remove_blank_line_dups.R
remove_blank_line_dups.RdThis function removes blank line duplicates (e.g., a "" line, followed by
another "" line) from a file.
It can also remove blank lines at the top or bottom of the file, and remove blank lines around a text block.
Usage
remove_blank_line_dups(
file,
remove_caps = TRUE,
block_fix = TRUE,
block_start_pattern = "<!-- badges: start -->",
block_end_pattern = "<!-- badges: end -->"
)Arguments
- file
A string indicating a file path.
- remove_caps
A
logicalflag indicating if the function should remove blank lines at the top and bottom of the file.- block_fix
A
logicalflag indicating if the function should fix blank lines around a text block- block_start_pattern
A string indicating the start of the text block.
- block_end_pattern
A string indicating the end of text block.
See also
Other file functions:
identify_blank_line_neighbors(),
normalize_hashtags(),
normalize_names(),
peek_csv_file(),
replace_in_file(),
sort_files_by_size(),
split_file(),
split_files_by_size(),
zip_files_by_pattern()
Examples
file <- tempfile()
writeLines(c("", "line 1", "", "", "line 2", "", "", "line 3", ""), file)
remove_blank_line_dups(file)
readLines(file)
#> [1] "line 1" "" "line 2" "" "line 3"
#> [1] "line 1" "" "line 2" "" "line 3" # Expected