sink {base} R Documentation

Send R Output to a File

Description


sink diverts R output to a connection (and stops such diversions).

Usage

sink(
    file = NULL,
    append = FALSE,
    split = TRUE,
    unsafe = TRUE);

Arguments

file

a writable connection Or a character String naming the file To write To, Or NULL To Stop sink-ing. [as string]

append

logical. If TRUE, output will be appended to file; otherwise, it will overwrite the contents of file. [as boolean]

split

logical: if TRUE, output will be sent to the new sink and to the current output stream, like the Unix program tee. [as boolean]

Details

sink diverts R output to a connection (and must be used again to finish such a diversion, see below!). If file is a character string, a file connection with that name will be established for the duration of the diversion.

Normal R output (To connection stdout) Is diverted by the Default type = "output". Only prompts And (most) messages Continue To appear On the console. Messages sent To stderr() (including those from message, warning And Stop) can be diverted by sink(type = "message") (see below).

sink() Or sink(file = NULL) ends the last diversion (of the specified type). There Is a stack of diversions for normal output, so output reverts to the previous diversion (if there was one). The stack Is of up to 21 connections (20 diversions).

If file Is a connection it will be opened If necessary (In "wt" mode) And closed once it Is removed from the stack Of diversions.

split = TRUE only splits R output (via Rvprintf) And the default output from writeLines: it does Not split all output that might be sent To stdout().

Sink-ing the messages stream should be done only with great care. For that stream file must be an already open connection, And there Is no stack of connections.

If file Is a character String, the file will be opened Using the current encoding. If you want a different encoding (e.g., To represent strings which have been stored In UTF-8), use a file connection — but some ways To produce R output will already have converted such strings To the current encoding.

Authors

SMRUCC genomics Institute

Value

sink returns NULL.

clr value class

Examples


[Package base version 2.33.856.6961 Index]