In R, there are common cases of this error: "The value of SET_STRING_ELT () should be" CHARSXP ", not a" character ""

I am struggling with a strange problem in R. I am using an old version of Rcpp to integrate R with some C ++ (unfortunately updating is not an option!), The Rcpp that I use is the old RccpTemplate. However, I doubt the problem is there.

I have some R code that works fine in most cases, but sometimes (especially when processing a lot of data) it fails mysteriously with Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'character'

It always fails in list operations, for example:

 res[["blabla"]] = r 

But if I use options(error=recover) and try to do the same after the error, the assignment can be completed without problems. C ++ uses only numeric vectors and in fact the code from assignments that fail fails far from time.

So my vague question is: what are the most common causes of this behavior? Bad memory? Bad objects (possibly bad RcppResultSet )? I have problems with attacking this problem ...

For completeness:

 platform i386-pc-solaris2.10 arch i386 os solaris2.10 system i386, solaris2.10 status major 2 minor 10.1 year 2009 month 12 day 14 svn rev 50720 language R 
+8
r rcpp
source share
1 answer

This is due to an error in the C code, probably in the package you are using (and not in R itself). Either the C code is not written correctly, and you only sometimes evaluate this branch of code, or the C code is written incorrectly and it corrupts the memory. This probably requires the C debugger; I'm not sure about Solaris, but on Linux I would create a script that reliably reproduces the error (this may take some work, but is an important step), then do

 R -d gdb gdb> r # (r)un R > ^C ## cntrl-C key, breaks into the debugger gdb> b Rf_error # set breakpoint when error occurs; tab completion available gdb> c # continue in R > source("test-script.R") # [error occurs] gdb> bt # backtrace -- current call stack, from Rf_error entry gdb> up # move up the stack; use this to get to package C code 

and then carefully analyze the code, especially looking at the misuse of PROTECT . See gdb help . I highly recommend updating R and your packages as the bugs will be fixed and you are going to spend a considerable amount of time on this.

+12
source share

All Articles