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

Reply via email to