textConnection
Text Connections

Description

Input and output text connections.

Usage

textConnection(object, open = "r", local = FALSE,
               encoding = c("", "bytes", "UTF-8"))
textConnectionValue(con)

Arguments

object a character vector to read for an input text connection. Equivalent to reading each element of the character vector as a line of input, or a variable name or NULL for an output text connection.
open a character string to specify the open mode. "r" or "" specifies read-only mode and opens an input text connection. "w" or "a" specifies write- /append -only mode and opens an output text connection.

local a logical value. Used only for an output text connection. If TRUE, the output text is assigned to a variable in the current environment. If FALSE, the output text is assigned to a variable in the global environment.
encoding a character string to specify the encoding for an input text connection. In R, the default "" specifies that the input texts are handled according to the current locale, "bytes" specifies that the input strings are read as bytes, and "UTF-8" specifies that the input strings are read as via UTF-8 encoding. This argument is not implemented in Spotfire Enterprise Runtime for R. Rather, the text characters are read directly from the object strings. If this argument is given as "bytes", a warning is generated.
con an output text connection object.

Details

textconnectionValue retrieves the character vector of an output text connection.
Value
textConnectionreturns an object of class c("textConnection", "connection").
textConnectionValuereturns a character vector that contains the output text.
References
Chambers, John M. 1998. Programming with Data. New York, NY: Springer.
See Also
connection, rawConnection, readLines, writeLines
Examples
tc.input <- textConnection(month.abb)
readLines(tc.input, 4)
scan(tc.input, what="", 3)
scan(tc.input, what="", 5)
close(tc.input)

tc.output <- textConnection("month.num", open = "w") writeLines(c("1", "2", "3"), tc.output) month.num textConnectionValue(tc.output) # same as "month.num" scan(tc.output, what="", 3) # cannot read from this output connection: close(tc.output)

# Append to "month.num" tc.output.a <- textConnection("month.num", open = "a") writeLines(as.character(1:6), tc.output.a) writeLines("This is the end of database", tc.output.a) month.num textConnectionValue(tc.output.a) # same as above. close(tc.output.a)

# Append to internal character vector tc.output.b <- textConnection(NULL, open = "a") writeLines(as.character(1:6), tc.output.b) writeLines("This is the end of database", tc.output.b) textConnectionValue(tc.output.b) close(tc.output.b)

Package base version 6.1.1-7
Package Index