<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.7600.16588">
<STYLE>@font-face {
        font-family: 宋体;
}
@font-face {
        font-family: Verdana;
}
@font-face {
        font-family: @宋体;
}
@page Section1 {size: 595.3pt 841.9pt; margin: 72.0pt 90.0pt 72.0pt 90.0pt; layout-grid: 15.6pt; }
P.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; FONT-SIZE: 10.5pt
}
LI.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; FONT-SIZE: 10.5pt
}
DIV.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; FONT-SIZE: 10.5pt
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
        FONT-STYLE: normal; FONT-FAMILY: Verdana; COLOR: windowtext; FONT-WEIGHT: normal; TEXT-DECORATION: none; mso-style-type: personal-compose
}
DIV.Section1 {
        page: Section1
}
BLOCKQUOTE {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em
}
OL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
UL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
</STYLE>
</HEAD>
<BODY style="FONT-FAMILY: verdana; FONT-SIZE: 10pt">
<DIV><FONT color=#0000ff size=2 face=Verdana>Thanks for your help! When will the 
new version 0.8.3 be released?</FONT></DIV>
<DIV><FONT size=2 face=Verdana></FONT>&nbsp;</DIV>
<DIV align=left>
<DIV align=left><FONT size=2 face=Verdana>
<HR style="WIDTH: 122px; HEIGHT: 2px" SIZE=2>
</FONT></DIV>
<DIV><FONT color=#c0c0c0><FONT size=2 
face=Verdana><SPAN>xiagao1982</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Verdana>2010-06-16</FONT></FONT></DIV></DIV>
<DIV><FONT size=2 face=Verdana>
<HR>
</FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2><STRONG>发件人:</STRONG> Romain 
Francois</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2><STRONG>发送时间:</STRONG> 
2010-06-16&nbsp;17:15:35</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2><STRONG>收件人:</STRONG> 
xiagao1982</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2><STRONG>抄送:</STRONG> 
rcpp-devel</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2><STRONG>主题:</STRONG> Re: [Rcpp-devel] About 
calling C/C++ functions in R</FONT></FONT></DIV>
<DIV><FONT size=2 face=Verdana></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Verdana>
<DIV>Le&nbsp;16/06/10&nbsp;10:56,&nbsp;Romain&nbsp;Francois&nbsp;a&nbsp;écrit&nbsp;:</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;Hi,</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;I&nbsp;totally&nbsp;second&nbsp;Dirk&nbsp;in&nbsp;the&nbsp;advice&nbsp;about&nbsp;reading&nbsp;the&nbsp;appropriate</DIV>
<DIV>&gt;&nbsp;documents.&nbsp;I&nbsp;would&nbsp;add&nbsp;the&nbsp;book&nbsp;from&nbsp;John&nbsp;Chambers&nbsp;"Programming&nbsp;with</DIV>
<DIV>&gt;&nbsp;Data"&nbsp;as&nbsp;it&nbsp;has&nbsp;very&nbsp;clear&nbsp;chapters&nbsp;about&nbsp;R&nbsp;and&nbsp;C(++).</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;Once&nbsp;you&nbsp;digested&nbsp;these&nbsp;documents,&nbsp;you&nbsp;can&nbsp;read&nbsp;the&nbsp;Rcpp-modules</DIV>
<DIV>&gt;&nbsp;vignette&nbsp;from&nbsp;Rcpp,&nbsp;which&nbsp;might&nbsp;help&nbsp;you.</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;Also,&nbsp;I&nbsp;just&nbsp;commited&nbsp;some&nbsp;code&nbsp;in&nbsp;Rcpp&nbsp;(which&nbsp;will&nbsp;be&nbsp;available&nbsp;in&nbsp;the</DIV>
<DIV>&gt;&nbsp;next&nbsp;version&nbsp;of&nbsp;Rcpp&nbsp;:&nbsp;0.8.3)&nbsp;that&nbsp;adds&nbsp;the&nbsp;Rcpp::InternalFunction</DIV>
<DIV>&gt;&nbsp;class,&nbsp;that&nbsp;you&nbsp;can&nbsp;use&nbsp;like&nbsp;this:</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;//&nbsp;grab&nbsp;the&nbsp;global&nbsp;environment</DIV>
<DIV>&gt;&nbsp;Environment&nbsp;g&nbsp;=&nbsp;Environment::global_env()&nbsp;;</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;//&nbsp;assign&nbsp;the&nbsp;"hello"&nbsp;R&nbsp;variable&nbsp;to&nbsp;the&nbsp;internal&nbsp;function</DIV>
<DIV>&gt;&nbsp;g["hello"]&nbsp;=&nbsp;InternalFunction(&nbsp;&amp;hello&nbsp;)&nbsp;;</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;Here&nbsp;is&nbsp;a&nbsp;complete&nbsp;example&nbsp;you&nbsp;can&nbsp;run&nbsp;from&nbsp;the&nbsp;R&nbsp;prompt:</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;require(&nbsp;Rcpp)</DIV>
<DIV>&gt;&nbsp;require(&nbsp;inline)</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;inc&nbsp;&lt;-&nbsp;'</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;const&nbsp;char*&nbsp;hello(&nbsp;std::string&nbsp;who&nbsp;){</DIV>
<DIV>&gt;&nbsp;std::string&nbsp;result(&nbsp;"hello&nbsp;"&nbsp;)&nbsp;;</DIV>
<DIV>&gt;&nbsp;result&nbsp;+=&nbsp;who&nbsp;;</DIV>
<DIV>&gt;&nbsp;return&nbsp;result.c_str()&nbsp;;</DIV>
<DIV>&gt;&nbsp;}</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;'</DIV>
<DIV>&gt;&nbsp;code&nbsp;&lt;-&nbsp;'</DIV>
<DIV>&gt;&nbsp;Environment&nbsp;g&nbsp;=&nbsp;Environment::global_env()&nbsp;;</DIV>
<DIV>&gt;&nbsp;g["hello"]&nbsp;=&nbsp;InternalFunction(&nbsp;&amp;hello&nbsp;)&nbsp;;</DIV>
<DIV>&gt;&nbsp;return&nbsp;R_NilValue&nbsp;;</DIV>
<DIV>&gt;&nbsp;'</DIV>
<DIV>&gt;&nbsp;fx&nbsp;&lt;-&nbsp;cxxfunction(&nbsp;signature(),&nbsp;code,&nbsp;inc,&nbsp;plugin&nbsp;=&nbsp;"Rcpp"&nbsp;)</DIV>
<DIV>&gt;&nbsp;f&nbsp;&lt;-&nbsp;fx()&nbsp;#&nbsp;force&nbsp;loading&nbsp;the&nbsp;dynamic&nbsp;library</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;hello(&nbsp;"world"&nbsp;)</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;I&nbsp;have&nbsp;not&nbsp;tried&nbsp;it&nbsp;yet&nbsp;from&nbsp;RInside.</DIV>
<DIV></DIV>
<DIV>Done.&nbsp;I&nbsp;added&nbsp;this&nbsp;as&nbsp;a&nbsp;new&nbsp;example&nbsp;"rinside_sample9.cpp".</DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV>//&nbsp;-*-&nbsp;mode:&nbsp;C++;&nbsp;c-indent-level:&nbsp;4;&nbsp;c-basic-offset:&nbsp;4;&nbsp;&nbsp;tab-width:&nbsp;8;&nbsp;-*-</DIV>
<DIV>//</DIV>
<DIV>//&nbsp;Simple&nbsp;example&nbsp;showing&nbsp;how&nbsp;expose&nbsp;a&nbsp;C++&nbsp;function</DIV>
<DIV>//</DIV>
<DIV>//&nbsp;Copyright&nbsp;(C)&nbsp;2010&nbsp;Dirk&nbsp;Eddelbuettel&nbsp;and&nbsp;Romain&nbsp;Francois</DIV>
<DIV></DIV>
<DIV>#include&nbsp;&lt;RInside.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;for&nbsp;the&nbsp;embedded&nbsp;R&nbsp;via&nbsp;RInside</DIV>
<DIV></DIV>
<DIV>//&nbsp;a&nbsp;c++&nbsp;function&nbsp;we&nbsp;wish&nbsp;to&nbsp;expose&nbsp;to&nbsp;R</DIV>
<DIV>const&nbsp;char*&nbsp;hello(&nbsp;std::string&nbsp;who&nbsp;){</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::string&nbsp;result(&nbsp;"hello&nbsp;"&nbsp;)&nbsp;;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result&nbsp;+=&nbsp;who&nbsp;;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;result.c_str()&nbsp;;</DIV>
<DIV>}</DIV>
<DIV></DIV>
<DIV>int&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])&nbsp;{</DIV>
<DIV></DIV>
<DIV>//&nbsp;create&nbsp;an&nbsp;embedded&nbsp;R&nbsp;instance</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RInside&nbsp;R(argc,&nbsp;argv);</DIV>
<DIV></DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;expose&nbsp;the&nbsp;"hello"&nbsp;function&nbsp;in&nbsp;the&nbsp;global&nbsp;environment</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R["hello"]&nbsp;=&nbsp;Rcpp::InternalFunction(&nbsp;&amp;hello&nbsp;)&nbsp;;</DIV>
<DIV></DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;call&nbsp;it&nbsp;and&nbsp;display&nbsp;the&nbsp;result</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::string&nbsp;result&nbsp;=&nbsp;R.parseEval("hello('world')")&nbsp;;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"hello(&nbsp;'world')&nbsp;=&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;result&nbsp;&lt;&lt;&nbsp;std::endl&nbsp;;</DIV>
<DIV></DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(0);</DIV>
<DIV>}</DIV>
<DIV></DIV>
<DIV></DIV>
<DIV>Romain</DIV>
<DIV></DIV>
<DIV></DIV>
<DIV>&gt;&nbsp;Romain</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;&nbsp;Le&nbsp;16/06/10&nbsp;02:13,&nbsp;xiagao1982&nbsp;a&nbsp;écrit&nbsp;:</DIV>
<DIV>&gt;&gt;&nbsp;Dear&nbsp;friends,</DIV>
<DIV>&gt;&gt;&nbsp;I&nbsp;am&nbsp;a&nbsp;newcomer&nbsp;of&nbsp;Rcpp&nbsp;and&nbsp;RInside.&nbsp;I&nbsp;installed&nbsp;them&nbsp;in&nbsp;my&nbsp;system&nbsp;and</DIV>
<DIV>&gt;&gt;&nbsp;successfully&nbsp;build&nbsp;the&nbsp;following&nbsp;example:</DIV>
<DIV>&gt;&gt;&nbsp;#include&nbsp;&lt;RInside.h&gt;&nbsp;//&nbsp;for&nbsp;the&nbsp;embedded&nbsp;R&nbsp;via&nbsp;RInside</DIV>
<DIV>&gt;&gt;&nbsp;Rcpp::NumericMatrix&nbsp;createMatrix(const&nbsp;int&nbsp;n)&nbsp;{</DIV>
<DIV>&gt;&gt;&nbsp;Rcpp::NumericMatrix&nbsp;M(n,n);</DIV>
<DIV>&gt;&gt;&nbsp;for&nbsp;(int&nbsp;i=0;&nbsp;i&lt;n;&nbsp;i++)&nbsp;{</DIV>
<DIV>&gt;&gt;&nbsp;for&nbsp;(int&nbsp;j=0;&nbsp;j&lt;n;&nbsp;j++)&nbsp;{</DIV>
<DIV>&gt;&gt;&nbsp;M(i,j)&nbsp;=&nbsp;i*10+j;</DIV>
<DIV>&gt;&gt;&nbsp;}</DIV>
<DIV>&gt;&gt;&nbsp;}</DIV>
<DIV>&gt;&gt;&nbsp;return(M);</DIV>
<DIV>&gt;&gt;&nbsp;}</DIV>
<DIV>&gt;&nbsp;&nbsp;&gt;</DIV>
<DIV>&gt;&gt;&nbsp;int&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])&nbsp;{</DIV>
<DIV>&gt;&gt;&nbsp;const&nbsp;int&nbsp;mdim&nbsp;=&nbsp;4;&nbsp;//&nbsp;let&nbsp;the&nbsp;matrices&nbsp;be&nbsp;4&nbsp;by&nbsp;4</DIV>
<DIV>&gt;&gt;&nbsp;SEXP&nbsp;ans;</DIV>
<DIV>&gt;&gt;&nbsp;RInside&nbsp;R(argc,&nbsp;argv);&nbsp;//&nbsp;create&nbsp;an&nbsp;embedded&nbsp;R&nbsp;instance</DIV>
<DIV>&gt;&gt;&nbsp;Rcpp::NumericMatrix&nbsp;M&nbsp;=&nbsp;createMatrix(mdim);&nbsp;//&nbsp;create&nbsp;and&nbsp;fill&nbsp;a&nbsp;sample</DIV>
<DIV>&gt;&gt;&nbsp;data&nbsp;Matrix</DIV>
<DIV>&gt;&gt;&nbsp;R["M"]&nbsp;=&nbsp;M;&nbsp;//&nbsp;assign&nbsp;C++&nbsp;matrix&nbsp;M&nbsp;to&nbsp;R's&nbsp;'M'&nbsp;var</DIV>
<DIV>&gt;&gt;&nbsp;std::string&nbsp;evalstr&nbsp;=&nbsp;"\</DIV>
<DIV>&gt;&gt;&nbsp;cat('Running&nbsp;ls()\n');&nbsp;print(ls());&nbsp;\</DIV>
<DIV>&gt;&gt;&nbsp;cat('Showing&nbsp;M\n');&nbsp;print(M);&nbsp;\</DIV>
<DIV>&gt;&gt;&nbsp;cat('Showing&nbsp;colSums()\n');&nbsp;Z&nbsp;&lt;-&nbsp;colSums(M);&nbsp;print(Z);&nbsp;\</DIV>
<DIV>&gt;&gt;&nbsp;Z";&nbsp;//&nbsp;returns&nbsp;Z</DIV>
<DIV>&gt;&gt;&nbsp;ans&nbsp;=&nbsp;R.parseEval(evalstr);&nbsp;//&nbsp;eval&nbsp;the&nbsp;init&nbsp;string&nbsp;--&nbsp;Z&nbsp;is&nbsp;now&nbsp;in&nbsp;ans</DIV>
<DIV>&gt;&gt;&nbsp;Rcpp::NumericVector&nbsp;v(ans);&nbsp;//&nbsp;convert&nbsp;SEXP&nbsp;ans&nbsp;to&nbsp;a&nbsp;vector&nbsp;of&nbsp;doubles</DIV>
<DIV>&gt;&gt;&nbsp;for&nbsp;(int&nbsp;i=0;&nbsp;i&lt;&nbsp;v.size();&nbsp;i++)&nbsp;{&nbsp;//&nbsp;show&nbsp;the&nbsp;result</DIV>
<DIV>&gt;&gt;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"In&nbsp;C++&nbsp;element&nbsp;"&nbsp;&lt;&lt;&nbsp;i&nbsp;&lt;&lt;&nbsp;"&nbsp;is&nbsp;"&nbsp;&lt;&lt;&nbsp;v[i]&nbsp;&lt;&lt;&nbsp;std::endl;</DIV>
<DIV>&gt;&gt;&nbsp;}</DIV>
<DIV>&gt;&gt;&nbsp;exit(0);</DIV>
<DIV>&gt;&gt;&nbsp;}</DIV>
<DIV>&gt;&gt;&nbsp;Now&nbsp;I&nbsp;add&nbsp;a&nbsp;function&nbsp;in&nbsp;the&nbsp;C++&nbsp;code:</DIV>
<DIV>&gt;&gt;&nbsp;const&nbsp;char*&nbsp;hello(&nbsp;std::string&nbsp;who&nbsp;){</DIV>
<DIV>&gt;&gt;&nbsp;std::string&nbsp;result(&nbsp;"hello&nbsp;"&nbsp;)&nbsp;;</DIV>
<DIV>&gt;&gt;&nbsp;result&nbsp;+=&nbsp;who&nbsp;;</DIV>
<DIV>&gt;&gt;&nbsp;return&nbsp;result.c_str()&nbsp;;</DIV>
<DIV>&gt;&gt;&nbsp;}</DIV>
<DIV>&gt;&gt;&nbsp;And&nbsp;I&nbsp;try&nbsp;to&nbsp;call&nbsp;this&nbsp;function&nbsp;in&nbsp;R:</DIV>
<DIV>&gt;&gt;&nbsp;std::string&nbsp;txt&nbsp;=&nbsp;"ret&nbsp;=&nbsp;hello('Friends');&nbsp;print(ret);";</DIV>
<DIV>&gt;&gt;&nbsp;R.parseEvalQ(txt);&nbsp;//&nbsp;eval&nbsp;string&nbsp;quietly,&nbsp;no&nbsp;result</DIV>
<DIV>&gt;&gt;&nbsp;It&nbsp;fails&nbsp;to&nbsp;do&nbsp;that.</DIV>
<DIV>&gt;&gt;&nbsp;Could&nbsp;you&nbsp;please&nbsp;tell&nbsp;me&nbsp;how&nbsp;to&nbsp;achieve&nbsp;that?&nbsp;Thanks&nbsp;very&nbsp;much!</DIV>
<DIV>&gt;&gt;&nbsp;Gao&nbsp;Xia</DIV>
<DIV>&gt;&gt;&nbsp;------------------------------------------------------------------------</DIV>
<DIV>&gt;&gt;&nbsp;xiagao1982</DIV>
<DIV>&gt;&gt;&nbsp;2010-06-16</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;</DIV>
<DIV></DIV>
<DIV></DIV>
<DIV>--&nbsp;</DIV>
<DIV>Romain&nbsp;Francois</DIV>
<DIV>Professional&nbsp;R&nbsp;Enthusiast</DIV>
<DIV>+33(0)&nbsp;6&nbsp;28&nbsp;91&nbsp;30&nbsp;30</DIV>
<DIV>http://romainfrancois.blog.free.fr</DIV>
<DIV>|-&nbsp;http://bit.ly/98Uf7u&nbsp;:&nbsp;Rcpp&nbsp;0.8.1</DIV>
<DIV>|-&nbsp;http://bit.ly/c6YnCi&nbsp;:&nbsp;graph&nbsp;gallery&nbsp;collage</DIV>
<DIV>`-&nbsp;http://bit.ly/bZ7ltC&nbsp;:&nbsp;inline&nbsp;0.3.5</DIV>
<DIV></DIV></FONT></DIV></BODY></HTML>