R - Connection (Stream)

Card Puncher Data Processing


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(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"     


  • stdin, stdout and stderr are the standard streams
  • class can be terminal or textConnection






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()))

Discover More
Card Puncher Data Processing
R - Read.Table

The Read.Table function reads a file in table format and creates a data frame from it, with cases corresponding to lines and variables to fields in the file. where: file can be a file, an Url or...
Card Puncher Data Processing
R - Readlines

Readlines reads lines of a text file and store them in a character vector. With a gzfile connection readLines can be useful for reading in lines of webpages

Share this page:
Follow us:
Task Runner