[Rd] How to debug an R package (with C code)

Hadley Wickham h.wickham at gmail.com
Fri Jan 17 15:35:54 CET 2014


>> Even if you are using a developer mode, sourcing an R file will have no
>> effect on a) the shared object library (DLL/so/dylib) available in the R
>> session, nor which shared objects are associated with the package. There
>> are ways to unload shared libraries within an R session, but personally I
>> tend to avoid them. The best way of being absolutely sure that the right
>> shared library is getting used is to reinstall the package, then close the
>> R session and restart.
>
> I value having a short turnaround time in debugging over such absolute
> surety, so I would recommend using load_all from Hadley's devtools
> package, which is usually able to recompile and reload the library
> without restarting R. I think the OP indicated that they are using
> RStudio, which should have a way to drive devtools (still, "source"
> would be the wrong command.)

In Rstudio, devtools::load_all() is bound to Cmd + shift + L. Rstudio
also provides Build and reload, which builds the package, restarts R
and reloads it.  This is a little slower than load_all(), but also a
little more accurate so can come in handy from time-to-time.

Hadley

-- 
http://had.co.nz/



More information about the R-devel mailing list