Skip to content

problems with for: warnings and segfault

7 messages · Peter Dalgaard, Ronaldo Reis-Jr., Brian Ripley +1 more

#
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:
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
[1]  5  6  7  8  9 10
[1] 5 5 5 5 5 5
The results are OK, but I dont understand the warning message

The second problem: The segfault
ycoord[indice] <- ycoord }
Segmentation fault

This is a R bug or an error in my for function?

Thanks
Ronaldo
#
"Ronaldo Reis-Jr." <chrysopa at gmail.com> writes:
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.
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]
#
Em Sex 11 Nov 2005 13:34, Peter Dalgaard escreveu:
I'm stupid, of course. The correct is:
This error is the segfault.

Thanks
Ronaldo
#
On Fri, 11 Nov 2005, Ronaldo Reis-Jr. wrote:

            
At step one you have xcoord[2] <- 5+1, so xcoord is c(5,6)
At step two you have xcoord[3] <- xcoord+2, so you are trying to replace 
one value with two, and the same for ycoord.
...

It is much better practice to create a vector with the size you are going 
to need it.
Both since R should not segfault, but mainly the latter.
#
On Fri, 11 Nov 2005, Ronaldo Reis-Jr. wrote:

            
All seg faults are bugs.

Mike
#
Mike Miller <mbmiller at taxa.epi.umn.edu> writes:
Within reason... If users go out of their way to cause havoc, e.g.
calling C/Fortran entry points with incorrect parameters, they deserve
what they get. "Normal" abuse of the language shouldn't crash R.
#
On Fri, 11 Nov 2005, Peter Dalgaard wrote:

            
Also, they are not necessarily bugs *in R*.  They could well be bugs in 
the compiler or the libc (or equivalent) or even the OS running out of 
resources ungracefully.  We've seen quite a few which were compiler bugs, 
and cases where a malloc failure was a segfault in the OS and not
a NULL return.

This one was a bug in R, only happening with incorrect usage.  It has now 
been fixed.