[Rcpp-devel] Success with integrating external C++ Code

Silkworth,David J. SILKWODJ at airproducts.com
Wed Oct 12 19:22:44 CEST 2011


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:armstrong.whit at gmail.com] 
Sent: Wednesday, October 12, 2011 1:20 PM
To: Silkworth,David J.
Cc: Steve Lianoglou; rcpp-devel at r-forge.wu-wien.ac.at
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 at krypton:~$ Rscript r.inline.r
Loading required package: inline
Loading required package: methods
Loading required package: Rcpp
$yourPhukkingX
[1] 1000

warmstrong at krypton:~$


On Wed, Oct 12, 2011 at 11:50 AM, Silkworth,David J.
<SILKWODJ at airproducts.com> 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
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>



More information about the Rcpp-devel mailing list