Rev 26314 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{textConnection}\alias{textConnection}\title{Text Connections}\description{Input and output text connections.}\usage{textConnection(object, open = "r", local = FALSE)}\arguments{\item{object}{character. A description of the connection.For an input this is an \R character vector object, and for an outputconnection the name for the \R character vector to receive theoutput.}\item{open}{character. Either \code{"r"} (or equivalently \code{""})for an input connection or \code{"w"} or \code{"a"} for an outputconnection.}\item{local}{logical. Used only for output connections. If \code{TRUE},output is assigned to a variable in the calling environment. Otherwisethe global environment is used.}}\details{An input text connection is opened and the character vector is copiedat time the connection object is created, and \code{close}destroys the copy.An output text connection is opened and creates an \R character vectorof the given name in the user's workspace or in the calling environment,depending on the value of the \code{local} argument. This object will at alltimes hold the completed lines of output to the connection, and\code{\link{isIncomplete}} will indicate if there is an incompletefinal line. Closing the connection will output the final line,complete or not. (A line is complete once it has been terminated byend-of-line, represented by \code{"\\n"} in \R.)Opening a text connection with \code{mode = "a"} will attempt toappend to an existing character vector with the given name in theuser's workspace or the calling environment. If none is found (evenif an object exists of the right name but the wrong type) a newcharacter vector wil be created, with a warning.You cannot \code{seek} on a text connection, and \code{seek} willalways return zero as the position.}\value{A connection object of class \code{"textConnection"} which inheritsfrom class \code{"connection"}.}\note{As output text connections keep the character vector up to dateline-by-line, they are relatively expensive to use, and it is oftenbetter to use an anonymous \code{\link{file}()} connection to collectoutput.On platforms where \code{vsnprintf} does not return the needed lengthof output (e.g., Windows) there is a 100,000 character limit on thelength of line for output connections: longer lines will be truncatedwith a warning.}\seealso{\code{\link{connections}}, \code{\link{showConnections}},\code{\link{pushBack}}, \code{\link{capture.output}}.}\examples{zz <- textConnection(LETTERS)readLines(zz, 2)scan(zz, "", 4)pushBack(c("aa", "bb"), zz)scan(zz, "", 4)close(zz)zz <- textConnection("foo", "w")writeLines(c("testit1", "testit2"), zz)cat("testit3 ", file=zz)isIncomplete(zz)cat("testit4\n", file=zz)isIncomplete(zz)close(zz)foo\dontrun{# capture R output: use part of example from help(lm)zz <- textConnection("foo", "w")ctl <- c(4.17, 5.58, 5.18, 6.11, 4.5, 4.61, 5.17, 4.53, 5.33, 5.14)trt <- c(4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69)group <- gl(2, 10, 20, labels = c("Ctl", "Trt"))weight <- c(ctl, trt)sink(zz)anova(lm.D9 <- lm(weight ~ group))cat("\nSummary of Residuals:\n\n")summary(resid(lm.D9))sink()close(zz)cat(foo, sep = "\n")}}\keyword{file}\keyword{connection}