Discussion:
[Rcpp-devel] Loading my own dynamic library using Module ?
Tama Ma
2010-12-04 10:25:03 UTC
Permalink
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
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
Romain Francois
2010-12-04 10:40:43 UTC
Permalink
Post by Tama Ma
Dear Rcpp developers,
I use gcc compiler and manage to compile my Rcpp-wrapped C++ code to /my/project/dir/lib/mod.so .
export R_LIBRARY_PATH= $R_LIBRARY_PATH:/my/project/dir/lib
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
Tama Ma
2010-12-04 11:10:00 UTC
Permalink
Dear Romain,

This works perfectly!
Thank you very much.

Best regards,
Tama Ma

(PS: Thank you for your advice on moving to R packages, and I will read on how to do that.)
Post by Romain Francois
Post by Tama Ma
Thank you very much.
Best regards,
Tama Ma
dll <- dyn.load( "/my/project/dir/lib/mod.so" )
mod <- Module( "mod", dll )
ETH Zurich
Tama Ma
Institüt für Theoretische Physik
HIT K 31.3
Wolfgang-Pauli-Strasse 27
ETH Hönggerberg
8093 Zürich
Switzerland

***@itp.phys.ethz.ch
www.phys.ethz.ch/~pingnang

+41 44 633 76 55 (Office Phone)
+41 44 633 11 15 (Office Fax)

Loading...