readLines
Read or Write Multiple Lines from or to a Connection

Description

Reads one more lines of text input from a connection.

Usage

readLines(con = stdin(), n = -1L, ok = TRUE, warn = TRUE,
          encoding = "unknown", skipNul = FALSE)

writeLines(text, con = stdout(), sep = "\n", useBytes = FALSE)

Arguments

con a connection. By default, the standard input for readLines and standard output for writeLines.
n an integer. The number of lines to read. The default -1L indicates readLines should read to the end of the file.
ok a logical value. If FALSE, and readLines reaches the end of the file before n lines are read, an error is generated. If TRUE (the default), no error is produced.
warn This argument is not yet implemented. a logical value. If flush=TRUE, this generates a warning if the final line read does not include a terminating new-line character.
encoding This argument is not yet implemented. the string encoding to use for newly-created strings. (See Encoding.)
text the character vector to write. Each element is written as one line.
sep a character string. The separator between lines. The default is "\n".
useBytes In TIBCO Enterprise Runtime for R, this argument is ignored. All strings are written using the encoding of the output connection.
skipNul A logical value specifying how to deal with nul (0) bytes in the input file.
  • If FALSE, then readLines warns about nul bytes, but also puts them into the output strings, thus terminating the string early.
  • If TRUE, then the nul bytes are omitted from the output strings.
If the connection encoding is one that normally includes nul bytes (such as UTF-16), this value is ignored, and these bytes are not skipped.

Details

See readline for information about reading a character string that is one line of input.
Value
readLinesreturns the lines of input (with no new-line characters) as elements of a character vector.
writeLinesreturns invisible(NULL).
See Also
readline, scan, Encoding.
Examples
tfile <- tempfile()
writeLines(paste(Sdatasets::state.abb, Sdatasets::state.name, sep=": ")[1:10],
    con=tfile)
readLines(tfile)
readLines(tfile, n=3)

conn <- file(tfile, "rt") readLines(conn, n=2) # first 2 lines readLines(conn, n=2) # next 2 lines close(conn) unlink(tfile)

Package base version 6.0.0-69
Package Index