readLines: Read text lines from a file

Description Usage Arguments Value See Also Examples

View source: R/readLines.R

Description

This is a drop in replacement for base::readLines() with restricted functionality. Compared to base::readLines() it:

Usage

1
readLines(con, n = -1, ok, warn, encoding, skipNul)

Arguments

con

A character string of the path to a file. Throws an error if a connection object is passed.

n

integer. The number of lines to read. A negative number means read all the lines in the file.

ok

Ignored, with a warning.

warn

Ignored, with a warning.

encoding

Ignored, with a warning.

skipNul

Ignored, with a warning.

Value

A UTF-8 encoded character vector of the lines in the file.

See Also

writeLines()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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))
close(con)

# Trying to use unsupported args throws a warning
data <- readLines(authors_file, encoding = "UTF-16")

Example output

Attaching package:brioThe following objects are masked frompackage:base:

    readLines, writeLines

Error : Only file paths are supported by brio::readLines()
Warning: `encoding` is ignored by brio::readLines()

brio documentation built on Dec. 11, 2021, 10:09 a.m.