[R] Controlling widths in write.fwf()

Vemuri, Aparna avemuri at epri.com
Wed Apr 15 22:00:48 CEST 2009


I was trying to format and write each line while looping over the entire
matrix; which made it terribly slow. Without the loop, it works fine.
Thanks Duncan.


-----Original Message-----
From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] 
Sent: Wednesday, April 15, 2009 10:04 AM
To: Vemuri, Aparna
Cc: r-help at r-project.org
Subject: Re: [R] Controlling widths in write.fwf()

On 4/15/2009 11:45 AM, Vemuri, Aparna wrote:
> Duncan
> I tried writeLines. But I need to print about 230000 lines and it is
> really slow. 

This took about 1 second here:

writeLines(as.character(1:230000), "C:/temp/test.txt")

I can't see how to make it much faster than that.

Duncan Murdoch

> 
> Thanks
> Aparna 
> 
> -----Original Message-----
> From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] 
> Sent: Tuesday, April 14, 2009 4:34 PM
> To: Vemuri, Aparna
> Cc: r-help at r-project.org
> Subject: Re: [R] Controlling widths in write.fwf()
> 
> On 14/04/2009 7:28 PM, Vemuri, Aparna wrote:
>> Is there a way to handle the widths of values being written to a file
>> using wrtite.fwf() ?
>> 
>> For example, I used read.fwf(file, width.vector) to read a file.
After
>> making the necessary data manipulation, I want to write the data to a
>> new file in the same width.vector format. Is there a way to specify
>> this?
> 
> There is no write.fwf function, but you can use sprintf() to convert 
> things to strings and writeLines to write those strings.  There's a
lot 
> of flexibility in the formats allowed; see the man page.
> 
> Duncan Murdoch
> 
> ______________________________________________
> 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.




More information about the R-help mailing list