tags:

views:

77

answers:

1

I have an R script that's usually started from the command line with arguments:

./script.R --width=10

It uses Rscript as interpreter:

#!/usr/bin/env Rscript 

Unfortunately it gives me a segmentation fault when it executes my compiled C code in R using .C("compiled_function").

So how can I run my R script with the gdb debugger attached?

Rscript apparently does not know the -d option.

I tried this

R -d gdb --vanilla --args --width=10 < script.R

But it didn't work since it passed the --width=10 to the debugger. What is the right call?

Maybe I should start R interactively:

$ R -d gdb --vanilla 

But then I don't know how to source my script and pass the arguments (--width=10).

A: 

I think a general GNU getopt convention is to use -- to denote remaining arguments. So try

 R -d gdb --vanilla -- --width=10 < script.R

Else hardwire the argument value in your script or compiled function.

Dirk Eddelbuettel
When I try that, for some reason, the R code in script.R is interpreted by gdb, which is a mess. There must be a way to call this thing without hardwiring the argument values in my script (I have actually quite many arguments, not just the one I gave in the example).
Then don't use redirect. Fire up `R -d gdb` and do `source("script.R")` instead.
Dirk Eddelbuettel
But how can I pass the options to the script, then? If I just say `source("script.R")` it will complain that the values ("width", etc.) are not set.
Maybe set them at the very top?
Dirk Eddelbuettel