Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

transform_lines_enc

Transform a text file


Description

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.

Usage

transform_lines_enc(
  path,
  fun,
  file_encoding = "UTF-8",
  ok = TRUE,
  skipNul = FALSE,
  write_back = TRUE,
  verbose = interactive()
)

Arguments

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 n > 0 lines are read? If not, an error will be generated.

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?

Value

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)

See Also

Other file functions: read_lines_enc(), write_lines_enc()


enc

Portable Tools for 'UTF-8' Character Data

v0.2.2
GPL-3
Authors
Kirill Müller [aut, cre]
Initial release
2019-12-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.