[R] when to use textConnection ??

Joshua Wiley jwiley.psych at gmail.com
Mon Aug 16 19:06:42 CEST 2010


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 <juanpide at 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 at 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list