[Rcpp-devel] Using loess() from Rcpp

Davor Cubranic cubranic at stat.ubc.ca
Thu Apr 8 00:03:17 CEST 2010

Thank you both, Dirk and Romain, for the advice and to Romain for adding the Formula class. And I apologize for the unclear question. I was asking two or three things, but none of them directly. That's what happens when I try to fire off an email late in the afternoon the last workday before a vacation.

What I had meant was, firstly, how to pass the formula to 'loess'. I appreciate Romain's adding the Formula class, and will use it once it's out in a release. In the meantime, I actually read the R docs a bit more carefully, and realized I could just use the 'formula' function, i.e., Function("formula")("y~x"). But using the Formula class is cleaner and more readable, so I'll switch once I can.

As for my DSL remark, I still think it would be nice to have a C++ operator that worked like R's '~' and produced a Formula instance from NumericVectors. It's not important, really -- maybe it's something I could attempt once I understand meta-templates and Rcpp's internals. Although, as I think about it, I've no idea how it could be done, given that 'y' and 'x' in 'y~x' are just symbols that have no connection to my NumericVector instances 'x' and 'y'.

Lastly, I was wondering if anyone had just used 'loess_raw' directly from Rcpp code, without going through R and 'loess' at all. Again, this may be something I'll explore down the road if I really have to, since I now have code that does the right thing simply and works correctly. :-)


On 2010-04-02, at 9:25 PM, Dirk Eddelbuettel wrote:

> On 1 April 2010 at 17:04, Davor Cubranic wrote:
> | Has anyone here used R curve-fitting from Rcpp? Like loess(), for example?
> | Reading the R code, after a couple of layers of preliminaries to extract all
> | the required parameters, it ends up in C (loess_raw) and Fortran (lowesw and
> | lowesp). 
> I read your mail briefly while I was gone [ which included two well-received
> talks about Rcpp / RInside on the west coast :) ], and now that I got back
> into town I still don't fully understand what you want.
> You do have function objects, as well as examples/functionCallback/ -- is
> that good enough?  It allows you to call just about any R function via Rcpp,
> but of course it doesn't magically make it faster.
> And in case you are coming from C++ rather than R: look at RInside.
> | It would be nice if there were already code out there that gives me a
> | tidier interface that I could use instead of transcribing the R wrapper
> | into C. And even cooler if R's 'formula' DSL had a C++ equivalent... 
> Well but R source was written to be used from R so ... I still don't quite
> understand what you are expecting.  That Rcpp rewrites all of R for you?
> Anyway, Romain kindly added formula objects to Rcpp as well. So maybe that
> will help you along, and more examples or use cases would be fine too.
> Cheers, Dirk
> -- 
>  Registration is open for the 2nd International conference R / Finance 2010
>  See http://www.RinFinance.com for details, and see you in Chicago in April!

More information about the Rcpp-devel mailing list