writeLines {base} R Documentation

## Write Lines to a Connection

### Description

Write text lines to a connection.

### Usage

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


### Arguments

 text A character vector con A connection object or a character string. sep character string. A string to be written to the connection after each line of text. useBytes logical. See ‘Details’.

### Details

If the con is a character string, the function calls file to obtain a file connection which is opened for the duration of the function call. (tilde expansion of the file path is done by file.)

If the connection is open it is written from its current position. If it is not open, it is opened for the duration of the call in "wt" mode and then closed again.

Normally writeLines is used with a text-mode connection, and the default separator is converted to the normal separator for that platform (LF on Unix/Linux, CRLF on Windows). For more control, open a binary connection and specify the precise value you want written to the file in sep. For even more control, use writeChar on a binary connection.

useBytes is for expert use. Normally (when false) character strings with marked encodings are converted to the current encoding before being passed to the connection (which might do further re-encoding). useBytes = TRUE suppresses the re-encoding of marked strings so they are passed byte-by-byte to the connection: this can be useful when strings have already been re-encoded by e.g. iconv. (It is invoked automatically for strings with marked encoding "bytes".)

connections, writeChar, writeBin, readLines, cat