[R] Controlling widths in write.fwf()

Vemuri, Aparna avemuri at epri.com
Wed Apr 15 17:45:46 CEST 2009


Duncan
I tried writeLines. But I need to print about 230000 lines and it is
really slow. 

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




More information about the R-help mailing list