connections
Functions to Manipulate Connections

Description

Creates, opens, or closes connections.

Usage

file(description = "", open = "", blocking = TRUE, 
   encoding = getOption("encoding"), raw = FALSE)
pipe(description, open = "", encoding = getOption("encoding"))
fifo(description, open = "", blocking = FALSE, 
   encoding = getOption("encoding"))
gzfile(description, open = "", encoding = getOption("encoding"), 
   compression = 6)
unz(description, filename, open = "", encoding = getOption("encoding"))
bzfile(description, open = "", encoding = getOption("encoding"), 
   compression = 9)
xzfile(description, open = "", encoding = getOption("encoding"), 
   compression = 6)
url(description, open = "", blocking = TRUE, 
   encoding = getOption("encoding"),
   method = getOption("url.method", "default"))
socketConnection(host = "localhost", port, server = FALSE, 
   blocking = FALSE, open = "a+", encoding = getOption("encoding"))
open(con, ...)
open.connection(con, open = "r", blocking = TRUE, ...)
isOpen(con, rw = "")
isIncomplete(con)
close(con, ...)
close.connection(con, type = "rw", ...)
flush(con)
flush.connection(con)
print.connection(x, ...)
summary.connection(object, ...)
stdin()
stdout()
stderr()
isatty(con)

Arguments

description a character string. Usually a file path or a URL to manipulate. It can be "clipboard" to read from the clipboard, "stdin" to read from 'standard input', or the empty string "" to create a temporary file (with open mode "w+" or "w+b") that will be deleted when closed. For functions that manipulate compressed files, description is the path to the compressed file.
open a character string. Specifies how to open the connection. See Details for all possible values. For unz, connections can be opened for reading only.
blocking a logical value. If TRUE, input or output operations on the connection should be blocked until the desired input or output is complete. This is currently unsupported, and will generate a warning if it is specified.
encoding a character string. Specifies the character encoding for the connection. Used for converting between bytes read and written to the connection and characters in strings. This can be any of the encodings accepted by iconv, including "native.enc".
filename a character string. In unz, this is the name of the file to be extracted from the zip file (specified by the description argument).
raw a logical flag. If TRUE, uses a 'raw' interface to manipulate a file.
compression an integer. The value should between 0 to 9, inclusive. Indicates the amount of compression to use when writing.
method a character string. Specifies the method to use to retrieve the contents of the URL. Supported methods are "default", "internal", "libcurl", and "wininet". The "wininet" method is supported only on Windows systems.
host a character string. Specifies the host name to connect to.
port a integer. Specifies which port number to connect to the host.
server a logical flag.
  • If TRUE, it creates a server socket.
  • If FALSE (the default), it creates a client socket.
con a connection object.
rw a character string. Specifies the mode to "read" or "write". Can be empty.
type a character string. Ignored.
x a connection object.
object a connection object.

Details

The following functions create connections: The following functions manage the connection as described:
open opens a connection and keeps the connection in an open status.
close closes a connection.
flush flushes the data into the connection.
The argument open can be set to one of the following values:
"r" or "rt" reading in text mode.
"w" or "wt" writing in text mode.
"a" or "at" appending in text mode.
"rb" reading in binary mode.
"wb" writing in binary mode.
"ab" appending in binary mode.
"r+" or "a+b" reading and writing.
"w+" or "w+b" reading and writing, but the file will be truncated initially.
"a+" or "a+b" reading and appending.
Value
filereturns a connection object with class attribute "connection". (see the Value for stdin for more information).
pipethis is currently unsupported, and will generate an error if it is called.
fifothis is currently unsupported, and will generate an error if it is called.
urlreturns a connection object with class attribute "connection".
gzfilereturns a connection object with class attribute "connection".
bzfilereturns a connection object with class attribute "connection".
unzreturns a connection object with class attribute "connection".
socketConnectionreturns a connection object with class attribute "connection".
stdinreturns a connection object, with class attribute "connection", to the standard input stream. Note the following exception: if the engine is run in non-interactive mode, with the script specified via -e or -f, stdin() is read as an empty stream. To access the actual input stream directly, use file('stdin','r').
stdoutreturns a connection object, with class attribute "connection", to the standard output stream.
stderrreturns a connection object, with class attribute "connection", to the standard error stream.
openhas no return value.
closehas no return value.
flushhas no return value.
isOpenreturns a logical value to indicate if the connection is open.
isIncompletereturns a logical value to indicate whether the last read attempt was blocked or there is unflushed output. Currently defined to always return FALSE.

isattyreturns a logical value. Returns TRUE if the connection is a terminal connection.
Differences between Spotfire Enterprise Runtime for R and Open-source R
References
Chambers, John M. 1998. Programming with Data. New York, NY: Springer.
See Also
readLines, writeLines, cat, sink, scan, parse, read.dcf, dput, dump, writeLines, readBin, writeBin, readChar, writeChar, load, save, iconv.
Examples
tmp <- tempfile()
con <- file(tmp, "w")
cat("write data", file = con, sep = "\n")
isOpen(con)
# TRUE
close(con)
readLines(tmp)
# [1] "write data"
unlink(tmp)
## Not run: unz("zippath", "filename", "r") 
Package base version 6.1.4-13
Package Index