No subject


Tue Oct 4 10:05:25 CEST 2011


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. <
SILKWODJ at airproducts.com> 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: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
> >
>
> _______________________________________________
> 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
>

--bcaec501673f6561c604af210262
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hello David,<br><br>Yes, Whit&#39;s example is great.<br><br>From my own sh=
ort experience, I would advise to stick to Whit&#39;s example closely. For =
instance, try not to separate a class between e.g. .h and .cpp, as inline s=
eems 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&#39;s fired.)<br>
<br>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 &#39;includes&#39; argument of cxxfunction, if there is a probl=
em with finding an object try juggling them, etc.<br>
<br>Also, watch out for templates and static variables with inline. (The la=
tter 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 tak=
ing an alternative approach as it might be easier for you. <br>
<br>There is definitely a right way to go about it though, and once you sta=
rt to get it the thing works great.<br><br>Simon<br><br><br><br><div class=
=3D"gmail_quote">On Wed, Oct 12, 2011 at 6:22 PM, Silkworth,David J. <span =
dir=3D"ltr">&lt;<a href=3D"mailto:SILKWODJ at airproducts.com">SILKWODJ at airpro=
ducts.com</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex;">Thanks Whit,<br>
<br>
Actually, it had been my fault not to notice your elegant use of inline.<br=
>
But this is good. =A0It helps to prototype inline, before converting to pac=
kage.<br>
The debug and edit cycle is much faster using inline.<br>
<br>
Dave<br>
<div><div></div><div class=3D"h5"><br>
-----Original Message-----<br>
From: Whit Armstrong [mailto:<a href=3D"mailto:armstrong.whit at gmail.com">ar=
mstrong.whit at gmail.com</a>]<br>
Sent: Wednesday, October 12, 2011 1:20 PM<br>
To: Silkworth,David J.<br>
Cc: Steve Lianoglou; <a href=3D"mailto:rcpp-devel at r-forge.wu-wien.ac.at">rc=
pp-devel at r-forge.wu-wien.ac.at</a><br>
Subject: Re: [Rcpp-devel] Success with integrating external C++ Code<br>
<br>
if you want it to be inline, then simply copy the contents of the .hpp<br>
and .cpp files into your R script and quote them.<br>
<br>
what the getModel function does is simply read the file into a string.<br>
<br>
I do it this way because emacs knows how to properly indent the file<br>
if I keep it separate (rather than as inline quoted text).<br>
<br>
here&#39;s a concise inline example for you:<br>
<br>
&lt;code&gt;<br>
require(inline)<br>
require(Rcpp)<br>
src &lt;-<br>
&#39;<br>
class Foo {<br>
double x_;<br>
public:<br>
Foo(double x): x_(x) {}<br>
const double getAdjX() const { return x_ *10; }<br>
};<br>
<br>
double x_ =3D Rcpp::as&lt;double&gt;(x);<br>
Foo myfoo(x_);<br>
return Rcpp::List::create(Rcpp::Named(&quot;yourPhukkingX&quot;,myfoo.getAd=
jX()));<br>
&#39;<br>
foo &lt;- cxxfunction(signature(x=3D&quot;numeric&quot;), body=3Dsrc, plugi=
n=3D&quot;Rcpp&quot;)<br>
print(foo(x=3D100))<br>
&lt;/code&gt;<br>
<br>
which you can then run as follows (after saving that snip to the file<br>
r.inline.r):<br>
warmstrong at krypton:~$ Rscript r.inline.r<br>
Loading required package: inline<br>
Loading required package: methods<br>
Loading required package: Rcpp<br>
$yourPhukkingX<br>
[1] 1000<br>
<br>
warmstrong at krypton:~$<br>
<br>
<br>
On Wed, Oct 12, 2011 at 11:50 AM, Silkworth,David J.<br>
&lt;<a href=3D"mailto:SILKWODJ at airproducts.com">SILKWODJ at airproducts.com</a=
>&gt; wrote:<br>
&gt; I see, but this is not truly an inline example is it?<br>
&gt;<br>
&gt;<br>
&gt; <a href=3D"https://github.com/armstrtw/CppBugs/tree/master/test/r.inli=
ne.example" target=3D"_blank">https://github.com/armstrtw/CppBugs/tree/mast=
er/test/r.inline.example</a><br>
&gt;<br>
&gt; Does that elucidate the things that need elucidating for you?<br>
&gt;<br>
&gt; -steve<br>
&gt;<br>
&gt; --<br>
&gt; Steve Lianoglou<br>
&gt; Graduate Student: Computational Systems Biology<br>
&gt; =A0| Memorial Sloan-Kettering Cancer Center<br>
&gt; =A0| Weill Medical College of Cornell University<br>
&gt; Contact Info: <a href=3D"http://cbio.mskcc.org/%7Elianos/contact" targ=
et=3D"_blank">http://cbio.mskcc.org/~lianos/contact</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Rcpp-devel mailing list<br>
&gt; <a href=3D"mailto:Rcpp-devel at lists.r-forge.r-project.org">Rcpp-devel at l=
ists.r-forge.r-project.org</a><br>
&gt; <a href=3D"https://lists.r-forge.r-project.org/cgi-bin/mailman/listinf=
o/rcpp-devel" target=3D"_blank">https://lists.r-forge.r-project.org/cgi-bin=
/mailman/listinfo/rcpp-devel</a><br>
&gt;<br>
<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href=3D"mailto:Rcpp-devel at lists.r-forge.r-project.org">Rcpp-devel at lists.=
r-forge.r-project.org</a><br>
<a href=3D"https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcp=
p-devel" target=3D"_blank">https://lists.r-forge.r-project.org/cgi-bin/mail=
man/listinfo/rcpp-devel</a></div></div></blockquote></div><br>

--bcaec501673f6561c604af210262--


More information about the Rcpp-devel mailing list