R - Connection (Stream)
About
Data are read in using connection interfaces:
- file,
- gzfile, (a file compressed with gzip)
- bzfile, (a file compressed with bzip2)
- url (an HTTP location)
showConnections
showConnections(all = TRUE)
description class mode text isopen can read can write
0 "stdin" "terminal" "r" "text" "opened" "yes" "no"
1 "stdout" "terminal" "w" "text" "opened" "no" "yes"
2 "stderr" "terminal" "w" "text" "opened" "no" "yes"
3 "letters" "textConnection" "r" "text" "opened" "yes" "no"
where:
- stdin, stdout and stderr are the standard streams
- class can be terminal or textConnection
getConnection
getConnection(what)
where:
- what is a row number of the showconnections output.
closeAllConnections
closeAllConnections()
stdin(), stdout() and stderr()
stdin(), stdout() and stderr() return connection objects.
stdin() refers to the “console” and not to the C-level “stdin” of the process. To access to the C-level file stream “stdin”, use file(“stdin”).
How to
know if the connection is connected to a terminal
The isatty function returns true if the connection is one of the class “terminal” connections and it is apparently connected to a terminal, otherwise false. This may not be reliable in embedded applications, including GUI consoles.
> c(isatty(stdin()), isatty(stdout()), isatty(stderr()))
[1] FALSE FALSE FALSE