Many thanks Romain!  It worked.  And thanks for pointing out the errors.<br><br>best<br>abhisek<br><br><div class="gmail_quote">On Thu, Mar 25, 2010 at 12:45 PM, Romain Francois <span dir="ltr">&lt;<a href="mailto:romain@r-enthusiasts.com">romain@r-enthusiasts.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Le 25/03/10 13:16, Abhisek a écrit :<div class="im"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi, Im not sure if this is the right place to post this.<br>
</blockquote>
<br></div>
It is not. The Rcpp-devel mailing list is the right place:<br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I am using Xubuntu<br>
Karmic Koala and am trying to use the Rcpp package.  I am testing it using a<br>
simple code that takes in a vector and adds 1 to each element:<br>
<br>
#include&lt;Rcpp.h&gt;<br>
<br>
// This file takes in a vector and adds one to each entry<br>
RcppExport SEXP addone(SEXP vec){<br>
<br>
     // create a local copy of vec<br>
     Rcpp::NumericVector orig(vec);<br>
<br>
     // create an output vector<br>
     Rcpp::NumericVector vecout(orig.size());<br>
<br>
     for(i=0;i&lt;orig.size();i++) {<br>
         vecout[i] = orig[i]+1;<br>
     }<br>
<br>
     Rcpp::Pairlist<br>
res(Rcpp::Named(&quot;result&quot;,vecout),Rcpp::Named(&quot;original&quot;,orig));<br>
<br>
     return res;<br>
}<br>
</blockquote>
<br></div>
You need some flags set up :<br>
<br>
export PKG_LIBS=`Rscript -e &quot;Rcpp:::LdFlags()&quot;`<br>
export PKG_CXXFLAGS=`Rscript -e &quot;Rcpp:::CxxFlags()&quot;`<div class="im"><br>
R CMD SHLIB addone.cpp<br>
<br></div>
also, your code is not correct since the i variable is not declared, so I get this when I try to compile it:<br>
<br>
addone.cpp: In function ‘SEXPREC* addone(SEXPREC*)’:<br>
addone.cpp:12: error: ‘i’ was not declared in this scope<br>
make: *** [addone.o] Error 1<br>
<br>
<br>
The inline package can help you with this when prototyping your code, check the cfunction in the inline package, specifically its arguments &quot;verbose&quot; and &quot;Rcpp&quot;.<br>
<br>
<br>
<br>
<br>
<br>
Personally I would code this using stl algorithms rather than raw looping:<br>
<br>
#include &lt;Rcpp.h&gt;<br>
<br>
template &lt;typename T&gt;<br>
inline T add_one( T x){<br>
        return x + 1 ;<div class="im"><br>
}<br>
<br>
// This file takes in a vector and adds one to each entry<br>
RcppExport SEXP addone(SEXP vec){<br>
<br></div>
    // original object<br>
    Rcpp::NumericVector orig(vec);<br>
<br>
    // output vector<div class="im"><br>
    Rcpp::NumericVector vecout(orig.size());<br>
<br></div>
    std::transform(<br>
        orig.begin(), orig.end(),<br>
        vecout.begin(),<br>
        add_one&lt;double&gt; ) ;<br>
<br>
    return vecout ;<br>
}<br>
<br>
<br>
or maybe you don&#39;t even have to write the tedious add_one template and you can do it like this:<div class="im"><br>
<br>
#include &lt;Rcpp.h&gt;<br>
<br>
// This file takes in a vector and adds one to each entry<br>
RcppExport SEXP addone(SEXP vec){<br>
<br></div>
    // original object<br>
    Rcpp::NumericVector orig(vec);<br>
<br>
    // output vector<div class="im"><br>
    Rcpp::NumericVector vecout(orig.size());<br>
<br></div>
    std::transform(<br>
        orig.begin(), orig.end(),<br>
        vecout.begin(),<br>
        std::bind2nd( std::plus&lt;double&gt;(), 1.0 )<br>
        ) ;<br>
<br>
    return vecout ;<div><div></div><div class="h5"><br>
}<br>
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I then try to use - R CMD SHLIB addone.cpp<br>
that didnt work.  the error said there was no such file  - &quot;Rcpp.h&quot; .<br>
Then i came across Dirk Eddelbeutel&#39;s beamer presentation and followed the<br>
suggestion to copy Rcpp.h to /usr/loca/include and libRcpp.so to<br>
/usr/local/lib<br>
Then i tried R CMD SHLIB addone.cpp again but got many errors.  Here is a<br>
small selection:<br>
<br>
/usr/local/include/Rcpp.h:34:32: error: RcppDatetimeVector.h: No such file<br>
or directory<br>
/usr/local/include/Rcpp.h:35:23: error: RcppFrame.h: No such file or<br>
directory<br>
/usr/local/include/Rcpp.h:36:26: error: RcppFunction.h: No such file or<br>
directory<br>
/usr/local/include/Rcpp.h:37:22: error: RcppList.h: No such file or<br>
directory<br>
<br>
could someone help?  im afraid im new both to linux and Rcpp!<br>
<br>
best,<br>
abhisek<br>
</blockquote>
<br>
<br></div></div><font color="#888888">
-- <br>
Romain Francois<br>
Professional R Enthusiast<br>
+33(0) 6 28 91 30 30<br>
<a href="http://romainfrancois.blog.free.fr" target="_blank">http://romainfrancois.blog.free.fr</a><br>
|- <a href="http://tr.im/OIXN" target="_blank">http://tr.im/OIXN</a> : raster images and RImageJ<br>
|- <a href="http://tr.im/OcQe" target="_blank">http://tr.im/OcQe</a> : Rcpp 0.7.7<br>
`- <a href="http://tr.im/O1wO" target="_blank">http://tr.im/O1wO</a> : highlight 0.1-5<br>
<br>
</font></blockquote></div><br>