[R] Memory problem

Manfred W. Baumstark maba at ukl.uni-freiburg.de
Fri Dec 7 19:10:11 CET 2001

Dear all,

I have written a little R program to convert images. See below. Within the
loop over j (the filenames) memory consumption grows constantly. rm( ... )
inside the loop did not help. Memory does not grow if I remove the writeBin
statements between the two #-------- marks. But obviously this is not
solution I want... 

Thanks for any advice. 

Manfred Baumstark
P.S. As I'm new to R: what sort of tests can I make to trace the problem?

Configuration: R-gui 1.3.1, WinNT 4.0, the same happens in R under IRIX 6.5
# Read list of filenames made by ls -1 <exp> >filelist
cfn <- file("filelist", "rt")
fn <- readLines(cfn, n = -1, ok = TRUE)
pad <- integer(length = 384)

for (j in 1:length(fn)) { 

  img <- file(fn[j], "rb")  	
  header <- readChar(img,8192)		
  imv <- readBin(img, "integer", n=1536*1536, size=2, signed=FALSE,
  imm <- matrix(imv, nrow=1536, ncol=1536)

  imout <- file(paste("test_", fn[j], sep=""), "wb")  	
  writeChar(header, imout, nchars = 512, eos = NULL) 

  for (i in 1:1536) {  
    writeBin(pad, imout, size=2, endian="big")
    writeBin(imm[,i], imout, size=2, endian="big")
    writeBin(pad, imout, size=2, endian="big")
  rm( img, header, imv, imm, imout, i)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: maba.vcf
Type: text/x-vcard
Size: 356 bytes
Desc: Card for Manfred W. Baumstark
Url : https://stat.ethz.ch/pipermail/r-help/attachments/20011207/2ae484ae/maba.vcf

More information about the R-help mailing list