Push Text Back on to a Connection
Functions to push back text lines onto a connection, and to enquire how many lines are currently pushed back.
pushBack(data, connection, newLine = TRUE, encoding = c("", "bytes", "UTF-8")) pushBackLength(connection) clearPushBack(connection)
- a character vector.
- A connection.
- logical. If true, a newline is appended to each string pushed back.
- character. See details.
Several character strings can be pushed back on one or more occasions.
The occasions form a stack, so the first line to be retrieved will be
the first string from the last call to
pushBack. Lines which
are pushed back are read prior to the normal input from the
connection, by the normal text-reading functions such as
Pushback is only allowed for readable connections in text mode.
When character strings with a marked encoding (see
Encoding) are pushed back they are converted to the
current encoding if
encoding = "". This may involve
representing characters as if they cannot be
converted. They will be converted to UTF-8 if
"UTF-8" or left as-is if
encoding = "bytes".
clearPushBack()return nothing, invisibly.
pushBackLengthreturns the number of lines currently pushed back.
zz <- textConnection(LETTERS) readLines(zz, 2) pushBack(c("aa", "bb"), zz) pushBackLength(zz) readLines(zz, 1) pushBackLength(zz) readLines(zz, 1) readLines(zz, 1) close(zz)