[Rcpp-devel] Loading my own dynamic library using Module ?

Romain Francois romain at r-enthusiasts.com
Sat Dec 4 11:40:43 CET 2010


Le 04/12/10 11:25, Tama Ma a écrit :
> Dear Rcpp developers,
>
> 	I use gcc compiler and manage to compile my  Rcpp-wrapped C++ code  to  /my/project/dir/lib/mod.so .
>
> 	Now, I want to call it inside R. Is there a way to do something like:
> 		export R_LIBRARY_PATH= $R_LIBRARY_PATH:/my/project/dir/lib
>
> 	and call within R, say:
> 		>  require(Rcpp)
> 		>  mod<- Module("mod")
>
> 	Meanwhile, I tried googling around, and looking into the src code, but I haven't got an idea yet.
>
> 	Is there a fast solution, or may I help a bit?
>
> 	Thank you very much.
>
> Best regards,
> Tama Ma

I think you can use dyn.load:

dll <- dyn.load( "/my/project/dir/lib/mod.so" )
mod <- Module( "mod", dll )

But I would strongly advise you to create an R package to host the code.

An easy way to do this is to use the Rcpp.package.skeleton function.

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/gpCSpH : Evolution of Rcpp code size
|- http://bit.ly/hovakS : RcppGSL initial release
`- http://bit.ly/iaxTdO : parser 0.0-12




More information about the Rcpp-devel mailing list