[R] IO: streaming input data
jim holtman
jholtman at gmail.com
Sun Jan 25 01:45:58 CET 2009
Here is one way to do it:
> x <- readLines(textConnection("line 1
+ line 2
+ data table
+ 01000
+ 10110
+ 00011
+ end table
+ line 3
+ line 4"))
> start <- grep("data table", x)
> end <- grep("end table", x)
> # now read in only the data between limit
> input <- read.table(textConnection(x[(start + 1):(end - 1)]))
> closeAllConnections()
>
> input
V1
1 1000
2 10110
3 11
>
Uses 'textConnection'
On Sat, Jan 24, 2009 at 5:48 PM, jesse daniel <jdlecy at gmail.com> wrote:
>
> Hello -
>
> I need to read in some tables that are embedded within data files like this:
>
> line 1
> line 2
> data table
> 01000
> 10110
> 00011
> end table
> line 3
> line 4
>
> Is there any way to read just the data by telling an input device to start
> reading when it encounters the keyword "data table" and stop reading at "end
> table"?
>
> Thanks in advance,
> Jesse
> --
> View this message in context: http://www.nabble.com/IO%3A-streaming-input-data-tp21646179p21646179.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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list