remove_lines: Remove Lines From a File

View source: R/remove_lines.R

remove_linesR Documentation

Remove Lines From a File

Description

Delete lines from a file programmatically, for example from ‘.gitignore’.

Usage

remove_lines(
  file_path = file.path(".", ".gitignore"),
  pattern,
  overwrite = !fritools::is_false(getOption("packager")[["force"]])
)

Arguments

file_path

Path to the file.

pattern

A character vector of patterns.

overwrite

Overwrite the file on disk?

Value

Used for its side effects, returns the lines to be left in the file.

Examples

temp_file <- file.path(tempdir(), ".gitignore")
content <- c("doc", "Meta", ".RData", "*.tar.gz", "doc/*")
cat(content, sep = "\n")
writeLines(content, temp_file)
cat(remove_lines(temp_file,  c("^doc$", "^doc/.*$")), sep = "\n")
cat(readLines(temp_file), sep = "\n")

packager documentation built on Aug. 16, 2023, 5:08 p.m.