Hi, I'm new to R, and am trying to embed R into another application. I'm calling gev.fit() from the ismev package, and it is crashing somewhere inside it. gdb is not catching it, and valgrind is not showing any memory corruption issues. I suspect it's memory corruption, because it doesn't crash in exactly the same spot each time. I'm running R 2.12.2 on a 64 bit linux (Ubuntu 10.04) Also, before I make the gev.fit() call, I save out the R state using "save.image(....)", then load the image file into a standalone R on the console, and call gev.fit(), and it works fine. So, it's something to do with my app, and the R. I'm looking for hints/ideas/tricks/etc for debugging this. I'm starting to put print statements into the R code, and into the C code in R (src/main/optim.c), but it hasn't shown me the source of the problem. Thanks! Here is the code I'm using to initialize: putenv("R_HOME=/apps/R/install/lib64/R"); const char *R_argv[]= {"RInterfaceTest", "--gui=none", "--no-save", "--no-readline", "--silent"}; Rf_initialize_R(sizeof(R_argv)/sizeof(R_argv[0]), const_cast<char **>(R_argv)); setup_Rmainloop(); ParseStatus status; SEXP cmdSexp, cmdexpr = R_NilValue; int error; string rcommand = "f<-file(paste(tempdir(), \"/Routput.txt\", sep = \"\"), open=\"wt+\")\nsink(f)\n"; PROTECT(cmdSexp = allocVector(STRSXP, 1)); SET_STRING_ELT(cmdSexp, 0, mkChar(rcommand.c_str())); cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue)); for(int i = 0; i < length(cmdexpr); i++) { R_tryEval(VECTOR_ELT(cmdexpr, i),NULL,&error); } UNPROTECT(2); [[alternative HTML version deleted]]
You posted this message already. If you didn't get any responses based on that posting, I think it means nobody has any suggestions beyond what you're already doing. Debugging is hard sometimes, even if you approach it in the right way. A common source of hard-to-find bugs is the R garbage collection scheme: if you don't PROTECT an allocation, sometimes it will be overwritten before you're done with it, because you haven't told R you're using it. Running under gctorture() can sometimes trigger this sooner, but it's very slow. Duncan Murdoch On 12-02-01 10:24 AM, Dave Pugmire wrote:> Hi, > I'm new to R, and am trying to embed R into another application. > I'm calling gev.fit() from the ismev package, and it is crashing somewhere > inside it. > gdb is not catching it, and valgrind is not showing any memory corruption > issues. > I suspect it's memory corruption, because it doesn't crash in exactly the > same spot each time. > I'm running R 2.12.2 on a 64 bit linux (Ubuntu 10.04) > > Also, before I make the gev.fit() call, I save out the R state using > "save.image(....)", then load the image file into a standalone R on the > console, and call gev.fit(), and it works fine. > So, it's something to do with my app, and the R. > > I'm looking for hints/ideas/tricks/etc for debugging this. > I'm starting to put print statements into the R code, and into the C code > in R (src/main/optim.c), but it hasn't shown me the source of the problem. > > Thanks! > > > Here is the code I'm using to initialize: > > putenv("R_HOME=/apps/R/install/lib64/R"); > const char *R_argv[]= {"RInterfaceTest", "--gui=none", "--no-save", > "--no-readline", "--silent"}; > Rf_initialize_R(sizeof(R_argv)/sizeof(R_argv[0]), const_cast<char > **>(R_argv)); > > setup_Rmainloop(); > > ParseStatus status; > SEXP cmdSexp, cmdexpr = R_NilValue; > int error; > string rcommand = "f<-file(paste(tempdir(), \"/Routput.txt\", sep = \"\"), > open=\"wt+\")\nsink(f)\n"; > PROTECT(cmdSexp = allocVector(STRSXP, 1)); > SET_STRING_ELT(cmdSexp, 0, mkChar(rcommand.c_str())); > > cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1,&status, R_NilValue)); > for(int i = 0; i< length(cmdexpr); i++) > { > R_tryEval(VECTOR_ELT(cmdexpr, i),NULL,&error); > } > UNPROTECT(2); > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Hello, On Wed, Feb 01, 2012 at 10:24:23AM -0500, Dave Pugmire wrote:> Hi, > I'm new to R, and am trying to embed R into another application. > I'm calling gev.fit() from the ismev package, and it is crashing somewhere > inside it. > gdb is not catching it, and valgrind is not showing any memory corruption > issues.[...] valgrind? *shudder* ;-)> I suspect it's memory corruption, because it doesn't crash in exactly the > same spot each time. > I'm running R 2.12.2 on a 64 bit linux (Ubuntu 10.04)[...] You could analyze the coredump with gdb, if you allow one to be written. On Ubuntu the default is to set core size to 0 Bytes, so a crash will be silent. (I think this is also true on some (most? all?) other Linux distributions). You need to change this behaviour and then you might get some progress in your debugging attempts. Ciao, Oliver
On 1 February 2012 at 10:24, Dave Pugmire wrote: | Hi, | I'm new to R, and am trying to embed R into another application. | I'm calling gev.fit() from the ismev package, and it is crashing somewhere | inside it. | gdb is not catching it, and valgrind is not showing any memory corruption | issues. | I suspect it's memory corruption, because it doesn't crash in exactly the | same spot each time. | I'm running R 2.12.2 on a 64 bit linux (Ubuntu 10.04) | | Also, before I make the gev.fit() call, I save out the R state using | "save.image(....)", then load the image file into a standalone R on the | console, and call gev.fit(), and it works fine. | So, it's something to do with my app, and the R. | | I'm looking for hints/ideas/tricks/etc for debugging this. | I'm starting to put print statements into the R code, and into the C code | in R (src/main/optim.c), but it hasn't shown me the source of the problem. | | Thanks! | | | Here is the code I'm using to initialize: | | putenv("R_HOME=/apps/R/install/lib64/R"); | const char *R_argv[]= {"RInterfaceTest", "--gui=none", "--no-save", | "--no-readline", "--silent"}; | Rf_initialize_R(sizeof(R_argv)/sizeof(R_argv[0]), const_cast<char | **>(R_argv)); | | setup_Rmainloop(); | | ParseStatus status; | SEXP cmdSexp, cmdexpr = R_NilValue; | int error; | string rcommand = "f<-file(paste(tempdir(), \"/Routput.txt\", sep = \"\"), | open=\"wt+\")\nsink(f)\n"; | PROTECT(cmdSexp = allocVector(STRSXP, 1)); | SET_STRING_ELT(cmdSexp, 0, mkChar(rcommand.c_str())); | | cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue)); | for(int i = 0; i < length(cmdexpr); i++) | { | R_tryEval(VECTOR_ELT(cmdexpr, i),NULL,&error); | } | UNPROTECT(2); FWIW I think both littler and RInside use a bit more legwork to initialize the R engine they embed. The code is public, so you could look at that. And/or you could of course just use RInside to make your life easier... Dirk -- "Outside of a dog, a book is a man's best friend. Inside of a dog, it is too dark to read." -- Groucho Marx