[Experimental]

This 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.

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 logical flag indicating if the function should remove blank lines at the top and bottom of the file.

block_fix

A logical flag 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.

Value

An invisible NULL. This function don't aim to return values.

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