[R] Faster Printing Alternatives to 'cat'
Gundala Viswanath
gundalav at gmail.com
Sat Jan 17 15:55:46 CET 2009
Hi Hadley,
I had to do it by line. Because, in practice, I will
manipulate the figures and string before printing it.
And I can't bind these results into one new object,
because there are literally millions of this lines, and
R object can't handle that in my 4GB Ram memory.
I tried your suggestion already, I have memory problem
> x <- cbind(dat$V1, as.character(dat$V2))
Error: cannot allocate vector of size 4.2 Gb
Execution halted
- Gundala Viswanath
Jakarta - Indonesia
On Sat, Jan 17, 2009 at 11:39 PM, hadley wickham <h.wickham at gmail.com> wrote:
> On Sat, Jan 17, 2009 at 7:59 AM, gundalav <gundalav at gmail.com> wrote:
>> Dear Jim and all,
>>
>> Allow me to ask your expert opinion.
>>
>>
>> Using the data (16Mb) downloadable from here:
>>
>> http://drop.io/gundalav/asset/test-data-zip
>>
>>
>> It took this long under 1994.070Mhz Cpu Linux, using
>> "write.table"
>>
>>> proc.time() - ptm1
>> user system elapsed
>> 16581.833 5787.228 21386.064
>>
>>
>>
>> __MYCODE__
>>
>> args <- commandArgs(trailingOnly=FALSE)
>> fname <- args[3]
>> dat <- read.delim(fname, header=FALSE);
>>
>> output <- file('output_writetable.txt', 'w')
>>
>>
>> ptm1 <- proc.time()
>> for (i in 1:nrow(dat)) {
>>
>> #cat(dat$V1[i]," ", as.character(dat$V2[i]),"\n", sep="")
>> write.table(cbind(dat$V1[i], as.character(dat$V2[i])),
>> file=output, sep="\t", quote=FALSE, col.names=FALSE, row.names=FALSE)
>> }
>>
>> close(output)
>> proc.time() - ptm1
>> __END__
>>
>> Perhaps I misunderstood you. But seems that this is
>> truly slow. Is there a way I can speed it up?
>
> Don't do it line by line!
>
> write.table(dat[, c("V1", "V2")], file='output_writetable.txt',
> sep="\t", quote=FALSE, col.names=FALSE, row.names=FALSE)
>
> Hadley
>
> --
> http://had.co.nz/
>
More information about the R-help
mailing list