write-this: Write into or over a file

Description Usage Arguments Value Functions Examples

Description

Helpers to write into or over a new or pre-existing file. Designed mostly for for internal use. File is written with UTF-8 encoding.

Usage

1
2
3
write_union(path, lines, quiet = FALSE)

write_over(path, lines, quiet = FALSE)

Arguments

path

Path to target file. It is created if it does not exist, but the parent directory must exist.

lines

Character vector of lines. For write_union(), these are lines to add to the target file, if not already present. For write_over(), these are the exact lines desired in the target file.

quiet

Logical. Whether to message about what is happening.

contents

Character vector of lines.

Value

Logical indicating whether a write occurred, invisibly.

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
write_union("a_file", letters[1:3])
readLines("a_file")
write_union("a_file", letters[1:5])
readLines("a_file")

write_over("another_file", letters[1:3])
readLines("another_file")
write_over("another_file", letters[1:3])

## Not run: 
## will error if user isn't present to approve the overwrite
write_over("another_file", letters[3:1])

## End(Not run)

## clean up
file.remove("a_file", "another_file")

usethis documentation built on July 4, 2019, 5:05 p.m.