Reads a file from disk, applies a function on the contents, and optionally
writes the file back if different.
The line ending separator of the input file is used if it can be read and
contains at least one, otherwise native_eol()
is used.
transform_lines_enc( path, fun, file_encoding = "UTF-8", ok = TRUE, skipNul = FALSE, write_back = TRUE, verbose = interactive() )
path | A vector of file paths. |
---|---|
fun | A function that returns a character vector. |
file_encoding | The encoding to assume for the input file. |
ok | logical. Is it OK to reach the end of the connection before
|
skipNul | logical: should nuls be skipped? |
write_back | Should the results of the transformation be written back to the file? |
verbose | Should the function show a message with a list of changed files? |
A named logical vector of the same length as path
that indicates
if a file has changed (TRUE
or FALSE
), or if an error occurred (NA
)
Other file functions:
read_lines_enc()
,
write_lines_enc()