Skip to content

[Rcpp-devel] RFC: Rcpp modules vs. RefClass

3 messages · Christian Gunning, Whit Armstrong, Dirk Eddelbuettel

#
Whit,

I see that this could be useful in similar situations where Rcpp modules
excels (generating R bindings to existing C++ classes). Language preference
aside, it's less clear to me what advantage this approach (or Rcpp modules)
offers average users over RefClasses + Rcpp functions, where the RefClass
holds state, and the Rcpp functions operate on the state using by-reference
semantics.

-Christian

On Tue, Nov 29, 2016 at 5:33 AM, Whit Armstrong <armstrong.whit at gmail.com>
wrote:

  
    
#
My point regarding the clang parser is that one really shouldn't have to
write any R or Rcpp wrappers at all.

If one directly parses the c++ class then both the R6/RefClass/List (or
whatever implementation one chooses to use) and the C wrappers (which we
will still need as we can't expose the c++ class directly to R; we still
need .Call) can be generated directly from parsing the class w/ clang.

Rcpp modules uses chaining to do this, but one still has to write this code:

    Rcpp::class_<Redis>("Redis")
        .constructor("default constructor")
        .constructor<std::string>("constructor with host port")
        .constructor<std::string, int>("constructor with host and port")
        .constructor<std::string, int, std::string>("constructor with host
and port and auth")
        .constructor<std::string, int, std::string, int>("constructor with
host and port, auth, and timeout")
        .method("exec", &Redis::exec,  "execute given redis command and
arguments")
...


richfitz/RcppR6 uses some yaml to generate the bindings, which one has to
provide and keep it synchronized w/ the class.

circle:
  constructor:
    args: [radius: double]
  methods:
    area:
      return_type: double
  active:
    circumference:
      name_cpp: circumference
      name_cpp_set: set_circumference
      access: member
      type: double
    radius: {access: field, type: double}


we should be able to extract all that from the class itself w/ clang.
That's the point.

-Whit
On Wed, Nov 30, 2016 at 5:49 AM, Christian Gunning <xian at unm.edu> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20161130/8b2a6a48/attachment.html>
#
On 30 November 2016 at 10:23, Whit Armstrong wrote:
| My point regarding the clang parser is that one really shouldn't have to write
| any R or Rcpp wrappers at all.

Did anybody keep tabs on the related projects by Duncan Temple Lang?

  https://github.com/omegahat/RClangSimple
  https://github.com/duncantl/Rllvm
  https://github.com/duncantl/RLLVMCompile

Yet another (ambitious !!) Google Summer of Code idea ...

Dirk