Hey, I asked this question on stackoverflow ( https://stackoverflow.com/questions/54234934/how-to-provide-a-custom-generator-constructor-for-an-rcpp-class) a while back but never got an answer, so I'm trying my luck here.
----- I've written R bindings for my C++ library, but for usability I would like to change the behavior of the methods and constructors somewhat in R: adding defaults and packing variables into a list. For example: instead of calling the generator ClassName(name, list(var1=1, var2=2)), I would like to have ClassName(name, var1=1, var2=2) Initially I was just using loadModules and using the C++ methods directly, but then switched to setRcppClass which allows me to override the methods including initialize. At first I tried using callNextMethod to no avail and then basically resorted to copy-pasting what the Rcpp provided initialize method does with some small adjustments. setRcppClass("ClassName", module="mymodule", methods=list( initialize=function(.Object, name, ...) { args <- list(...) argNames <- allNames(args) cppArgs <- nzchar(argNames) .CppObject <<- .CppGenerator$new(name, args[cppArgs]) }, show=function() { cat('ClassName of type:', .CppObject$name(), '\n') })) This does almost what I want, except that I need to explicitly name the name parameter: ClassName(name="Foo", var1=1, var2=2) Obviously I also want to avoid copying the Rcpp code, but instead call it somehow. Additionally R CMD check is complaining about all references to .CppGenerator .CppObject allNames ------- Thanks a lot in advance Tom Haber
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel