[R] Stack overflow in R 2.10.0 with sub()

Duncan Murdoch murdoch at stats.uwo.ca
Tue Oct 27 13:53:15 CET 2009

On 10/27/2009 8:15 AM, Kenneth Roy Cabrera Torres wrote:
> Hi R developers:
> Congratulations for the new R 2.10.0 version.
> It is a huge effort! Thank you for your work and dedication.
> I just want to ask how to make this "strip blank" function
> to work again (it works on R.2.9.2).
> alumnos$AL_NUME_ID<-sub("(^ +)|( +$)","",alumnos$AL_NUME_ID),)
> "alumnos" is a data base with 900.000 rows and 72 columns.
> and "alumnos$AL_NUME_ID" is a character variable read form
> a "mysql" database.
> The system shows me this message:
> Error: C produce desborde de pila en 'segfault'
> It seems a "stack overflow" problem, but it works on R 2.9.2!
> Thank you for your help, and again, thank you for your work!!!

I just tried that (after fixing the typo at the end of the line) and it 
worked on these vectors:

x <- c("a", " a", "a ", " a ")
y <- rep(x, 900000)

So there is something about your dataset that is causing the problem. 
Can you narrow it down?  Here are some tests:

1.  Check that it is the value that is causing the problem, not the 
manner of getting it:

x <- alumnos$AL_NUME_ID
y <- sub("(^ +)|( +$)","",x)

2.  See if it is in the first half of the data:

x <- alumnos$AL_NUME_ID
x <- x[seq_len(length(x)/2)]
y <- sub("(^ +)|( +$)","",x)

3.  See if it is in the second half:

x <- alumnos$AL_NUME_ID
x <- x[-seq_len(length(x)/2)]
y <- sub("(^ +)|( +$)","",x)

If you can narrow it down to a particularly short vector that causes the 
error, that would be very helpful.  It's likely to be somewhat tedious, 
because I imagine those segfaults will terminate R; I'd suggest using 
save.image() a lot when things are working, so you can restart after a 

Duncan Murdoch

More information about the R-help mailing list