[R] Unusual separators

Jim Holtman jholtman at gmail.com
Sat Aug 20 11:49:30 CEST 2011


In the current version (2.13.1) textConnection is much slower if you have a large file (>10000 lines) than using a temporary output file.  Try timing a script using the two different approachs to get an appreciation for the difference.

Sent from my iPad

On Aug 20, 2011, at 3:39, peter dalgaard <pdalgd at gmail.com> wrote:

> 
> On Aug 17, 2011, at 05:57 , Jim Holtman wrote:
> 
>> just read in the file using the tab as the separator.  if this is a problem because a tab might appear by itself, then use readLines to read in the file, gsub to replace the blank/tab with a new separator, writeLines to write out to a temporary and then read in from the temporary file.
> 
> You can skip the write and read back step by reading from a text connection. In R 2.14-to-be, there's a text= argument to read.table (and scan too), so you'll be able to do the whole thing on the fly: 
> 
> read.table(.... text=gsub(readLines(.....)....))
> 
> 
>> 
>> Sent from my iPad
>> 
>> On Aug 16, 2011, at 11:02, Matt Curcio <matt.curcio.ri at gmail.com> wrote:
>> 
>>> Hi all,
>>> I have a list that I got from a web page that I would like to crunch.
>>> Unfortunately, the list has some unusual separators in it.  I believe
>>> the columns are separated by 1 space and 1 tab.  I tried to insert
>>> this into the read.table( ..., sep=" \t", ...) but got an error that
>>> said something like 'only one byte separators can be used.
>>> I have thought about using a gsub to 'swap out' the "space + tab" and
>>> replace it with commas, etc but thought there might be another way.
>>> Any suggestions?
>>> M
>>> -- 
>>> 
>>> 
>>> Matt Curcio
>>> M: 401-316-5358
>>> E: matt.curcio.ri at gmail.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.
>> 
>> ______________________________________________
>> 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.
> 
> -- 
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
> "Døden skal tape!" --- Nordahl Grieg
> 
> 
> 
> 
> 
> 
> 



More information about the R-help mailing list