[Rcpp-devel] experimental handling of uncaught exceptions

Romain François francoisromain at free.fr
Tue Dec 29 09:14:01 CET 2009

On 12/28/2009 11:52 PM, Dirk Eddelbuettel wrote:
> On 28 December 2009 at 10:58, Romain François wrote:
> | Are there cases where the libRcpp.{so,a} is used but the Rcpp package is
> | not available ?
> I recalled having seen this question and that I never replied.  What exactly
> did you mean?
> What can happen is that
>       a) Rcpp is installed
>       b) other packages see Rcpp.h and libRcpp.so and can build against it
>       c) Rcpp ("the package") is never loaded

Right. It all comes down to whether the C code that builds against 
libRcpp.so can call the R function Rcpp:::cpp_exception.

After doing the magic trick of gathering the exception class and 
message, this gets called :

			has_exception_class ? Rf_mkString(exception_class.c_str()) : R_NilValue
		), R_FindNamespace(Rf_mkString("Rcpp"))
	) ;

so as long as the Rcpp package is loadable (not necessary loaded), 
things are fine.

> That is pretty common, I think. And it kinda makes the onAttach tricky (but
> then user can always do it).

We'll have to document that the user who wants to use the exception 
mechanism and not load the Rcpp package has to manually call the 
initUncaughtExceptionHandler C routine from their C(++) code or from R 
like thuis:

.Call( "initUncaughtExceptionHandler", PACKAGE= "Rcpp" )

> The Rcpp package is really several things:
>       d) an easy to get to the user via install.packages() and update.packages()
>       e) that gets them the lib and header as per b)
>       f) a minimal library that get loaded with the package -- but, and that
>          is important, only contains RcppExample() !!

ah ok. I understand it now.

> so I have thought about
>          splitting that off into a package RcppUsage or RcppExample or something
>          which would show how to build against Rcpp

That could be useful. Do you know that you can have as many R packages 
as you like in one r-forge project, just split the pkg directory.

> | We could have it all in C, but this leads to more complicated code. See
> | the file rJava.c attached for how Simon does it in rJava. (look between
> | hack and hack)
> I'd rather avoid C.

I was talking about C - as opposed to R - rather than C - as opposed to 
C++ -. As per above there is only an issue if the R code of the package 
is unreachable.

> Dirk

Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
|- http://tr.im/IlMh : CPP package: exposing C++ objects
|- http://tr.im/HlX9 : new package : bibtex
`- http://tr.im/Gq7i : ohloh

More information about the Rcpp-devel mailing list