Also, many R functions are designed to operate on R connections, to input and output text. Alternatively, we may wish to provide the input text as an R character vector, or output text to a character vector. The textConnection makes a character vector look like a connection, so R routines that operate on connections may also operate on character vectors.
The textConnection also provides a mechanism for re-encoding text data, although this may be more directly accomplished via the iconv function. However, both methods are currently limited to encodings that do not allow embedded null characters. -Matt On Mon, 2010-08-16 at 13:06 -0400, Joshua Wiley wrote: > Hi, > > One useful case is when data is sent in an email. For instance: > > T1 T2 T3 > -0.24 -0.26 -0.67 > -1.58 0.04 0.14 > -1.21 1.55 -0.45 > 0.31 0.48 -1.39 > > One could read it in via > > con <- textConnection(" > T1 T2 T3 > -0.24 -0.26 -0.67 > -1.58 0.04 0.14 > -1.21 1.55 -0.45 > 0.31 0.48 -1.39") > > read.table(con, header = TRUE) > > Often a text file can be read in directly with read.table() and the > appropriate delimiter (e.g., sep = "\t" for tab, "," for comma, etc.). > Do you have a particular problem you are trying to solve or an > application of textConnection() you are interested in? > > Cheers, > > Josh > > On Mon, Aug 16, 2010 at 9:37 AM, skan <juanp...@gmail.com> wrote: > > > > Hello. > > > > I don't uderstant when to use textConnection and when not. > > Some examples do it, some not. > > I've even seen something like > > > > con <- textConnection(rev(rev(ReadLines('data.txt'))[-(1:2])) > > data <- read.table(con) > > close(con) > > > > -- > > View this message in context: > > http://r.789695.n4.nabble.com/when-to-use-textConnection-tp2327132p2327132.html > > Sent from the R help mailing list archive at Nabble.com. > > > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > -- Matthew S. Shotwell Graduate Student Division of Biostatistics and Epidemiology Medical University of South Carolina ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.