Hello David, Yes, Whit's example is great.
>From my own short experience, I would advise to stick to Whit's example closely. For instance, try not to separate a class between e.g. .h and .cpp, as inline seems to sometimes throw in an extra include for the user class, but without the right path. (Might not always, but if you put them together you dodge the bullet before it's fired.) So generally keep things tight, if you have any redundant stl includes take them out, you should anyway. Be careful with the order you pass files through the 'includes' argument of cxxfunction, if there is a problem with finding an object try juggling them, etc. Also, watch out for templates and static variables with inline. (The latter are often not good style anyway to be honest, at least if you overuse them as I do.) I had trouble with both so if you find the same consider taking an alternative approach as it might be easier for you. There is definitely a right way to go about it though, and once you start to get it the thing works great. Simon On Wed, Oct 12, 2011 at 6:22 PM, Silkworth,David J. < [email protected]> wrote: > Thanks Whit, > > Actually, it had been my fault not to notice your elegant use of inline. > But this is good. It helps to prototype inline, before converting to > package. > The debug and edit cycle is much faster using inline. > > Dave > > -----Original Message----- > From: Whit Armstrong [mailto:[email protected]] > Sent: Wednesday, October 12, 2011 1:20 PM > To: Silkworth,David J. > Cc: Steve Lianoglou; [email protected] > Subject: Re: [Rcpp-devel] Success with integrating external C++ Code > > if you want it to be inline, then simply copy the contents of the .hpp > and .cpp files into your R script and quote them. > > what the getModel function does is simply read the file into a string. > > I do it this way because emacs knows how to properly indent the file > if I keep it separate (rather than as inline quoted text). > > here's a concise inline example for you: > > <code> > require(inline) > require(Rcpp) > src <- > ' > class Foo { > double x_; > public: > Foo(double x): x_(x) {} > const double getAdjX() const { return x_ *10; } > }; > > double x_ = Rcpp::as<double>(x); > Foo myfoo(x_); > return Rcpp::List::create(Rcpp::Named("yourPhukkingX",myfoo.getAdjX())); > ' > foo <- cxxfunction(signature(x="numeric"), body=src, plugin="Rcpp") > print(foo(x=100)) > </code> > > which you can then run as follows (after saving that snip to the file > r.inline.r): > warmstrong@krypton:~$ Rscript r.inline.r > Loading required package: inline > Loading required package: methods > Loading required package: Rcpp > $yourPhukkingX > [1] 1000 > > warmstrong@krypton:~$ > > > On Wed, Oct 12, 2011 at 11:50 AM, Silkworth,David J. > <[email protected]> wrote: > > I see, but this is not truly an inline example is it? > > > > > > https://github.com/armstrtw/CppBugs/tree/master/test/r.inline.example > > > > Does that elucidate the things that need elucidating for you? > > > > -steve > > > > -- > > Steve Lianoglou > > Graduate Student: Computational Systems Biology > > | Memorial Sloan-Kettering Cancer Center > > | Weill Medical College of Cornell University > > Contact Info: http://cbio.mskcc.org/~lianos/contact > > > > > > _______________________________________________ > > Rcpp-devel mailing list > > [email protected] > > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel > > > > _______________________________________________ > Rcpp-devel mailing list > [email protected] > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel >
_______________________________________________ Rcpp-devel mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
