<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>RE: Using Rcpp in C++</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">You obviously want to get stated.&nbsp; I have to assume that you use R, because you would not have found Rcpp any other way.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">Rcpp is a means of writing functions in C++ that R can call.&nbsp; So you don&#8217;t expect to compile a stand-alone program with main().</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">The easiest way to experience Rcpp is using inline code, we need to have the package &#8220;inline&#8221; installed so we can reference its library.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">Here is an R script that will do a little more than you wished.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">library(Rcpp)</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">library(inline)</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">src &lt;- '</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">RNGScope scope;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">Rcpp::IntegerVector num_rands(arg1);</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">Rcpp::NumericVector output(num_rands[0]);</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">output=runif( num_rands[0],0, 1 ) ;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">return output;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">'</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">&nbsp;test_function &lt;- cxxfunction(signature(arg1 = &quot;integer&quot;), src, plugin = &quot;Rcpp&quot;)</FONT></SPAN></P>
<BR>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">This script will create a function in your R session called test_function.&nbsp; You will not see it in the object list, but it is there.&nbsp; It takes a single integer argument.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">So after running the script above in the R Console you can then call the function like this:</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">test_function(5)</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Calibri">in the R Console.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">Soeren Vogel wrote:</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">Hello I want to experiment a little with Rcpp, however, as a newby I don't get it to work, e.g.:</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">#include &lt;iostream&gt;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">#include &lt;Rcpp.h&gt;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">int main()</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">{</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">&nbsp;&nbsp;&nbsp; using namespace Rcpp;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">&nbsp;&nbsp;&nbsp; RNGScope scope;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; runif( 1, 0, 1) &lt;&lt; std::endl;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">&nbsp;&nbsp;&nbsp; return 0;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">}</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Consolas">How can I get it to work? Thanks, S?ren</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN></P>

</BODY>
</HTML>