This is a drop in replacement for base::readLines() with restricted
functionality. Compared to base::readLines() it:
Only works with file paths, not connections.
Assumes the files are always UTF-8 encoded.
Does not warn or skip embedded nulls, they will likely crash R.
Does not warn if the file is missing the end of line character.
The arguments ok, warn, encoding and skipNul are ignored, with a warning.
readLines(con, n = -1, ok, warn, encoding, skipNul)A character string of the path to a file. Throws an error if a connection object is passed.
integer. The number of lines to read. A negative number means read all the lines in the file.
Ignored, with a warning.
Ignored, with a warning.
Ignored, with a warning.
Ignored, with a warning.
A UTF-8 encoded character vector of the lines in the file.
authors_file <- file.path(R.home("doc"), "AUTHORS")
data <- readLines(authors_file)
# Trying to use connections throws an error
con <- file(authors_file)
try(readLines(con))
#> Error : Only file paths are supported by brio::readLines()
close(con)
# Trying to use unsupported args throws a warning
data <- readLines(authors_file, encoding = "UTF-16")
#> Warning: `encoding` is ignored by brio::readLines()