Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run R script with gdb attached?

Tags:

r

debugging

gdb

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).

like image 745
Frank Avatar asked Sep 01 '10 13:09

Frank


1 Answers

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.

like image 160
Dirk Eddelbuettel Avatar answered Oct 06 '22 00:10

Dirk Eddelbuettel