[Rcpp-devel] How do I load a rcpp module?

Dirk Eddelbuettel edd at debian.org
Mon Mar 12 17:16:17 CET 2012


Glenn,

On 12 March 2012 at 16:33, Glenn Lawyer wrote:
| Dear Steve,
| 
| Thanks for a quick answer. Please see comments inline, below.
| 
| On 03/12/2012 10:54 AM, Steve Lianoglou wrote:
| 
|     You can try to load the shared library once you `R CMD
|     SHLIB` it using `dyn.load` (see ?dyn.load).
| 
| Yes, you can try this, but the example in the vingette does not include this
| step. The vingette has only
| >require(Rcpp)
| >mod <- Module("mod").
| 
| Which fails.
| 
| I would then guess, as you did, that I should load the compiled code, and that
| dyn.load is the proper command. Except this also fails:
| > require(Rcpp)
| Loading required package: Rcpp
| > dyn.load("test.so")
| > mod <- Module("mod")
| > mod$norm(3,4)
| Error in Module(module, mustStart = TRUE) :
|   Failed to initialize module pointer: Error in FUN("_rcpp_module_boot_mod"
| [[1L]], ...): no such symbol _rcpp_module_boot_mod in package .GlobalEnv
| 
| So I check the help text on dyn.load. Perhaps I need to load my shared library
| into the global env?

This was discusses in the last few weeks on the list -- feed what dyn.load()
gives you back to Module() via its PACKAGE argument.

But we really do recommend using a package.

| > dyn.load("test.so",local=FALSE)
| > mod <- Module("mod")
| > mod$norm(3,4)
| Error in Module(module, mustStart = TRUE) :
|   Failed to initialize module pointer: Error in FUN("_rcpp_module_boot_mod"
| [[1L]], ...): no such symbol _rcpp_module_boot_mod in package .GlobalEnv
| 
| fails.
| 
| 
|         This is, in fact, my main frustration with all of the rcpp documentation. It
|         consistently assumes a high level of sophistication from its users. Almost
|         none of the examples work "as is", nor do they give hints as to what
|         information is missing.
| 
|     I don't know how fair of a complaint that is ... at a minimum, I think
|     you should be familiar with the concepts in the "Writing R Extensions"
|     manual:
| 
|     http://cran.r-project.org/doc/manuals/R-exts.pdf
| 
|     and I don't think it's really unfair for the devs to assume that as a
|     starting point.
| 
| 
| Rcpp is a vast improvement over the older approach to writing R extensions, a
| point the developers are rightly proud of. Given that, it is inconsistent to
| expect intimately familiarity with the (now) obsolete approach in order to get
| even the most basic examples of the new approach to work.

Sorry: Modules is clearly NOT the most basic example.

| A vingette in which none of the examples work as written makes a very
| frustrating introduction to a topic, and one I would hesitate to pass on to my
| students.

The vignette code itself is executed when the vignette is compiled; and there
are the unit tests for you to look at.

You are welcome to contribute patches to the vignette to make it clearer and
better.  But Modules are indeed an advanced art, and a little finicky at
time, and also "work in progress". You don't have to use them.  Modules have
huge promise but it may not be for every situation.

Dirk

| 
| +glenn
| 
| 
| 
| On 03/12/2012 10:54 AM, Steve Lianoglou wrote:
| 
|     Hi Glenn,
| 
|     On Mon, Mar 12, 2012 at 5:26 AM, Glenn Lawyer <lawyer at mpi-inf.mpg.de> wrote:
| 
|         Dear List,
| 
|         I am working through the vingette "Exposing C++ functions and classes with
|         Rcpp modules," and am stuck at section 2.2.1.
| 
|         I create a text file with the code for the Uniform class, and successfully
|         compile it with R CMD SHLIB.
| 
|         Can you please tell me how to load it into R so that I can continue with the
|         example? The vingette clearly shows how to use it once everything is set up,
|         but does not show how to set things up.
| 
|     I suspect they want you to either whip the functionality you are using
|     to create a module from into a package of sorts (some documentation
|     for that is at the end of the vignette, but also in other (non
|     Module-specific) Rcpp vignettes).
| 
|     You can alternatively try to load the shared library once you `R CMD
|     SHLIB` it using `dyn.load` (see ?dyn.load). You will definitely need
|     to have Rcpp loaded in your workspace first, though.
| 
|     That may or may not work w/ modules, though ... I never tried, but:
| 
| 
|         This is, in fact, my main frustration with all of the rcpp documentation. It
|         consistently assumes a high level of sophistication from its users. Almost
|         none of the examples work "as is", nor do they give hints as to what
|         information is missing.
| 
|     I don't know how fair of a complaint that is ... at a minimum, I think
|     you should be familiar with the concepts in the "Writing R Extensions"
|     manual:
| 
|     http://cran.r-project.org/doc/manuals/R-exts.pdf
| 
|     and I don't think it's really unfair for the devs to assume that as a
|     starting point.
| 
|     I guess you're somehow right in the sense that reading through that
|     requires a bit of R sophistication, but what you're trying to do w/
|     Rcpp is sophisticated :-)
| 
|     Also, the examples using `inline` are the ones you can get away with
|     doing w/o having some R know-how, but once you get into the world of
|     trying to compile external C++ code and include it "seamlessly" into
|     R, you really should do a bit of h/w on the R library/package building
|     process (the R-exts doc above).
| 
|     Hope that helps,
|     -steve
| 
| 
| 
| --
| -----------------------------------
| It is difficult to find a black cat in a dark room,
| especially if there is no cat.
|   -- Chinese proverb
| 
|   Dr. Glenn Lawyer
|   +352 661 967 244
|   Max-Planck-Institut für Informatik
|   Computational Biology and Applied Algorithmics
|   Campus E1 4
|   66123 Saarbrücken, Germany
|   http://bioinf.mpi-inf.mpg.de/~lawyer
| 
| 
| 
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list