[Rcpp-devel] Bug: RcppArmadillo.package.skeleton builds faulty man/*.Rd files

Dirk Eddelbuettel edd at debian.org
Thu Jul 12 17:37:53 CEST 2012


On 12 July 2012 at 11:18, Nathan VanHoudnos wrote:
| Thanks for straightening me out about the documentation issues belonging to
| base R instead of Rcpp. I should have checked that first.
| 
| And your point about inline not really being a "package-able" thing makes
| sense. I was able to force my toy inlineExample package to install by
| 
|  1. using the `code_files` argument, 
|  2. deleting the `*.Rd` files in `man/` and 
|  3. modifying DESCRIPTION to include `inline` for `Depends:` and `LinkingTo:` 

You apparently still left the __use of inline__ in the package which makes no sense.

| 
| But then when I fire up a session of R and try to use it: 
| 
| 
|     > require(inlineExample)
|     Loading required package: inlineExample
|     Loading required package: Rcpp
|     Loading required package: RcppArmadillo
|     Loading required package: inline
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Wrong.

|     > plus.two.cpp( matrix(1:12, ncol=3))
|     Error in .Primitive(".Call")(<pointer: (nil)>, UmatrixR) : 
|       NULL value passed as symbol address
|     >
|     > plus.two.cpp
|     An object of class "CFunc"
|     function (UmatrixR) 
|     .Primitive(".Call")(<pointer: (nil)>, UmatrixR)
|     <environment: 0x2f28370>
|     Slot "code":
|     [1] "\n// includes from the plugin\n#include <RcppArmadillo.h>\n#include
|     <Rcpp.h>\n\n\n#ifndef BEGIN_RCPP\n#define BEGIN_RCPP\n#endif\n\n#ifndef
|     END_RCPP\n#define END_RCPP\n#endif\n\nusing namespace Rcpp;\n\n\n// user
|     includes\n\n\n// declarations\nextern \"C\" {\nSEXP file2f8c4cc10657( SEXP
|     UmatrixR) ;\n}\n\n// definition\n\nSEXP file2f8c4cc10657( SEXP UmatrixR ){\
|     nBEGIN_RCPP\n\n  arma::mat U = Rcpp::as<arma::mat>(UmatrixR);\n  return
|     (Rcpp::wrap(U+2));\n\nEND_RCPP\n}\n\n\n"
| 
| It fails. To my untrained eyes it seems that:
| 
|  1. the code that `inline` compiled never got copied by *.package.skeleton to
|     the "right" part of the directory skeleton for later compilation by the R
|     build process, and 
|  2. failing that the 'code_files' argument does not cause R to source those *.R
|     files when the package is loaded. 
| 
| Thinking about this further, it seems like (2) would be a really bad idea
| because it would force the user to compile the code every time they loaded
| their package. That would both exclude all users who require binary only
| packages and just simply be really inefficient. 
| 
| And (1) seems technically possible, but I don't know how involved that kind of
| fix would be. I seems like a really low priority edge case. How often do you

Right.

| have users who are sophisticated enough to try to make an R package that don't
| know how to translate their `inline` script to the more robust R build process?
| At least one! But probably not more than that... 

I only ever call Rcpp*.package.skeleton() with the name="" argument (and with
module=TRUE in the case of Rcpp modules).

If there is existing documentation suggestion that there is a layer that
automagically converts you inline-using code, let me know where you see that
and I will remove it.
 
| So I'll post this as a question on stackexchange so that people can easily find
| the answer. 

I am not sure this question can have an answer. If you want such a converter,
methinks you have to write it.
 
| Thanks for your help. Rcpp and its friends are really awesome. Thanks for
| building them and supporting them! 

Yup :) It is very useful to me too, which is how it all started.  

But as always need to tighten and straighten the documentation.  When you go
from inline to package, expect to edit your code by hand to complement it.
We _could_ write helpers for that (as signature() has information) but that
has not happened yet.

Cheers, Dirk
 
| Cheers,
| 
| Nathan
| 
| On Wed, Jul 11, 2012 at 8:32 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
| 
| 
|     Nathan,
| 
|     Two more comments. First, I am not sure you can even do what you did.
|      When I
|     call Rcpp.armadillo.package() as (where I omit the R file argument -- no
|     point including a file loading inline in a package, or redefining these
|     functions)
| 
|       RcppArmadillo.package.skeleton(name='inlineExample',list=c
|     ('plus.two.cpp','plus.two.r'))
| 
|     I get
| 
|     R> RcppArmadillo.package.skeleton(name='inlineExample',list=c
|     ('plus.two.cpp','plus.two.r'))
|     Creating directories ...
|     Creating DESCRIPTION ...
|     Creating NAMESPACE ...
|     Creating Read-and-delete-me ...
|     Saving functions and data ...
|     Making help files ...
|     Done.
|     Further steps are described in './inlineExample/Read-and-delete-me'.
| 
|     Adding RcppArmadillo settings
|      >> added Depends: Rcpp, RcppArmadillo
|      >> added LinkingTo: Rcpp, RcppArmadillo
|      >> added useDynLib directive to NAMESPACE
|      >> added Makevars file with Rcpp settings
|      >> added Makevars.win file with RcppArmadillo settings
|      >> added example header file using Rcpp/RcppArmadillo
|      >> added example src file using armadillo classes
|      >> added example R file calling the C++ example
|     Warning message:
|     In dump(item, file = file.path(code_dir, sprintf("%s.R", list0[item]))) :
|       deparse of an S4 object will not be source()able
|     R>
| 
| 
|     indicating the result from cxxfunction() will not be representable. And
|     indeed:
| 
|     edd at max:/tmp$ R CMD INSTALL inlineExample
|     * installing to library ‘/usr/local/lib/R/site-library’
|     * installing *source* package ‘inlineExample’ ...
|     ** libs
|     ccache g++-4.6 -I/usr/share/R/include -DNDEBUG   -I"/usr/local/lib/R/
|     site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/
|     include"   -fpic  -g -O0 -Wall -c rcpparma_hello_world.cpp -o
|     rcpparma_hello_world.o
|     g++-4.6 -shared -o inlineExample.so rcpparma_hello_world.o -L/usr/local/lib
|     /R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/
|     Rcpp/lib -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
|     installing to /usr/local/lib/R/site-library/inlineExample/libs
|     ** R
|     Error in parse(outFile) : 3:21: unexpected '<'
|     2: structure(function (UmatrixR)
|     3: .Primitive(".Call")(<
|                           ^
|     ERROR: unable to collate and parse R files for package ‘inlineExample’
|     * removing ‘/usr/local/lib/R/site-library/inlineExample’
|     edd at max:/tmp$
| 
|     That is is simply not supported. You have to subscribe your inline'd object
|     by hand.
| 
|     Second, and as for the manual page leading to an error: we can reproduce
|     that
|     via
| 
|       package.skeleton(name='pkgskelExample',list=c('plus.two.r'))
| 
|     which is free of any Rcpp-isms.  So this appears to be "simply" a bug in
|     R.
| 
|     Dirk
| 
|     --
|     Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
| 
| 
| 
| 
| --
| Nathan VanHoudnos
| |- Statistics & Public Policy PhD student
| |- Program for Interdisciplinary Education Research (PIER) Fellowship
| |- Carnegie Mellon University
| |- http://www.andrew.cmu.edu/user/nmv
| 
| "We may at once admit that any inference from the particular to the
|  general must be attended with some degree of uncertainty, but this
|  is not the same as to admit that such inference cannot be absolutely
|  rigorous, for the nature and degree of the uncertainty may itself be 
|  capable of rigorous expression."  -- R.A. Fisher
| 

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list