[R] problems with for: warnings and segfault
    Peter Dalgaard 
    p.dalgaard at biostat.ku.dk
       
    Fri Nov 11 16:34:10 CET 2005
    
    
  
"Ronaldo Reis-Jr." <chrysopa at gmail.com> writes:
> Hi,
> 
> I have two problem with a for looping using R Version 2.1.1  (2005-06-20) on a 
> Debian Linux Testing.
> 
> The first problem: warnings messages
> 
> Look:
> 
> > xcoord <- 5
> > ycoord <- 5
> > indice <- 1
> > for(i in c(1:5)) {indice <- indice+1;xcoord[indice] <- xcoord+i; 
> ycoord[indice] <- ycoord }
> Warning messages:
> 1: number of items to replace is not a multiple of replacement length 
> 2: number of items to replace is not a multiple of replacement length 
> 3: number of items to replace is not a multiple of replacement length 
> 4: number of items to replace is not a multiple of replacement length 
> 5: number of items to replace is not a multiple of replacement length 
> 6: number of items to replace is not a multiple of replacement length 
> 7: number of items to replace is not a multiple of replacement length 
> 8: number of items to replace is not a multiple of replacement length 
> 
> > xcoord
> [1]  5  6  7  8  9 10
> > ycoord
> [1] 5 5 5 5 5 5
> > 
> 
> The results are OK, but I dont understand the warning message
Look at
  xcoord[indice] <- xcoord+i
The left hand side is a single element, the right hand side is a
vector so I don't think it means what I think you think it means.
> The second problem: The segfault
> 
> > xcoord <- 5
> > ycoord <- 5
> > indice <- 1
> > for(i in c(1:100)) {indice <- indice+1;xcoord[indice] <- xcoord+i; 
> ycoord[indice] <- ycoord }
> Segmentation fault
> 
> This is a R bug or an error in my for function?
R shouldn't segfault no matter how silly the code....
[I see this on 2.2.0/Linux too, on the 2nd try of the for loop]
-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907
    
    
More information about the R-help
mailing list