{"id":198012,"date":"2013-10-18T19:21:03","date_gmt":"2013-10-18T15:21:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=198012"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=198012","title":{"rendered":"<span class=\"post_title\">\u041a\u0430\u043a \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 R \u0432 C++<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<i>R \u2014 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u0430\u044f \u0441\u0440\u0435\u0434\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 GNU \u00a9 Wikipedia. <\/i><\/p>\n<p>  \u0412 R \u0441\u043e\u0431\u0440\u0430\u043d\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043d\u0430 \u0432\u0441\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0436\u0438\u0437\u043d\u0438 \u0438 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u0440\u043e\u0434\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u044b: \u0435\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u044b, \u043a\u0430\u043a SPSS, Statistica, SAS, Wolfram Mathematica \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435. \u041a\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c R \u0432 \u0441\u0432\u043e\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f?<br \/>  \u041d\u0430 \u0445\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b\u0430 <a href=\"http:\/\/habrahabr.ru\/post\/161983\/\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043f\u0440\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 R \u0432 \u0421++, \u043e\u0434\u043d\u0430\u043a\u043e \u043e\u043d\u0430 \u043e\u0441\u0432\u0435\u0442\u0438\u043b\u0430 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u0448 \u043a\u043e\u0434 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434 GPL-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0439 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0435\u0439. \u041d\u043e \u0438 \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u0442\u044c \u0432\u044b\u0445\u043e\u0434 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u0430 Rserve.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>Rserve<\/h4>\n<p>  <a href=\"https:\/\/github.com\/s-u\/Rserve\">Rserve<\/a> \u2014 \u044d\u0442\u043e TCP\/IP \/ unix socket \u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 <a href=\"http:\/\/www.r-project.org\">R<\/a> \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043b\u0438\u043d\u043a\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0435\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438. \u041a\u043b\u0438\u0435\u043d\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u0434 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a C\/C++, Java, PHP. \u041a\u043e\u0434 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434 LGPL.<\/p>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c R \u0438 Rserve:  <\/p>\n<pre><code class=\"bash\"># sudo apt-get instal r-base # sudo R &gt; install.package(&quot;Rserve&quot;); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c Rserve:  <\/p>\n<pre><code class=\"bash\"># R CMD Rserve <\/code><\/pre>\n<p>  \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c  <\/p>\n<pre><code class=\"bash\"># R CMD Rserve.dbg <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 Rserve \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 TCP\/IP \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u0442\u0443 (6311). \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c unix sockets \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c Rserve \u0441 \u0444\u043b\u0430\u0433\u043e\u043c &#8212;RS-socket  <\/p>\n<pre><code class=\"bash\"># R CMD Rserve --RS-socket &quot;\/home\/zoberg\/mysocket&quot; <\/code><\/pre>\n<p>  \u0421\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0444\u043b\u0430\u0433\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043d\u0430\u0431\u0440\u0430\u0432  <\/p>\n<pre><code class=\"bash\"># R CMD Rserve --help <\/code><\/pre>\n<p>  <\/p>\n<h4>C++ \u043a\u043b\u0438\u0435\u043d\u0442<\/h4>\n<p>  C++ \u043a\u043b\u0438\u0435\u043d\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 4 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432: <a href=\"https:\/\/raw.github.com\/s-u\/Rserve\/master\/src\/client\/cxx\/Rconnection.h\">Rconnection.h<\/a> (\u0442\u0443\u0442 \u043b\u0435\u0436\u0430\u0442 \u0432\u0441\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0435), <a href=\"https:\/\/raw.github.com\/s-u\/Rserve\/master\/src\/Rsrv.h\">Rsrv.h<\/a>, <a href=\"https:\/\/github.com\/s-u\/Rserve\/blob\/master\/src\/include\/Win32\/config.h\">config.h<\/a> (\u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Windows), <a href=\"https:\/\/github.com\/s-u\/Rserve\/blob\/master\/src\/include\/sisocks.h\">sisocks.h<\/a> (\u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u043a\u0435\u0442\u044b) \u0438 \u043e\u0434\u043d\u043e\u0433\u043e <a href=\"https:\/\/raw.github.com\/s-u\/Rserve\/master\/src\/client\/cxx\/Rconnection.cc\">Rconnection.cc<\/a>. \u0412\u0437\u044f\u0442\u044c \u0438\u0445 \u0432\u0441\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e <a href=\"https:\/\/github.com\/s-u\/Rserve\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043d\u0430 guthub<\/a>.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0442\u0435\u043f\u0435\u0440\u044c <a href=\"https:\/\/raw.github.com\/s-u\/Rserve\/master\/src\/client\/cxx\/demo1.cc\">\u0434\u0435\u043c\u043e<\/a>, \u043e\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/p>\n<pre><code class=\"cpp\">\/\/\/ main.cpp #include &lt;iostream&gt; using std::cout;  #define MAIN                      \/\/ \u043a\u043ec\u0442\u044b\u043b\u044c \u0438\u0437 sisocks.h #define SOCK_ERRORS  \/\/ verbose socket errors  #include &quot;sisocks.h&quot; #include &quot;Rconnection.h&quot;  \/\/ \u0431\u0435\u0441\u0445\u0438\u0442\u0440\u043e\u0441\u0442\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 C++ API int main(int argc, char **argv) {     initsocks(); \/\/ \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434 Win32 - \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432 unix      \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a Rserve.      \/\/ \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e - &quot;127.0.0.1&quot;, 6311.     \/\/ \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c unix sockets, \u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:      \/\/ Rconnection *rc = new Rconnection(&quot;\/home\/zoberg\/mysocket&quot;, -1);     Rconnection *rc = new Rconnection();          int i=rc-&gt;connect();     if (i) {         char msg[128];         sockerrorchecks(msg, 128, -1);         printf(&quot;unable to connect (result=%d, socket:%s).\\n&quot;, i, msg); return i;     }         double d[6] = { 1.5, 2.4, 5.6, -1.2, 0.6, 1.7 };          \/\/ \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 &quot;a&quot; \u0432 R     Rdouble *rd = new Rdouble(d, 6);     rc-&gt;assign(&quot;a&quot;, rd);     delete rd;      \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 &quot;b&quot; \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 2 x 3 \u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u0430\u0442\u0440\u0438\u0446 b * t(b)     Rdouble *x = (Rdouble*) rc-&gt;eval(&quot;b&lt;-matrix(a,2); b%*%t(b)&quot;);          if (x) { \/\/ \u0435\u0441\u043b\u0438 \u0432\u0441\u0451 \u043f\u0440\u043e\u0448\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442         cout &lt;&lt; x &lt;&lt; &quot;\\n&quot;;                  \/\/ \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0439\u0441\u044f \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b         Rinteger *dim = (Rinteger*) x-&gt;attribute(&quot;dim&quot;);         if (dim)             cout &lt;&lt; dim-&gt;intAt(0) &lt;&lt; &quot; by &quot; &lt;&lt; dim-&gt;intAt(1) &lt;&lt; &quot; matrix\\n&quot;;                  \/\/ \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 (\u0431\u0435\u0437 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f)         double *d = x-&gt;doubleArray();         int i=0, ct = x-&gt;length();         while (i &lt; ct) {             cout &lt;&lt; d[i++] &lt;&lt; &quot; &quot;;          }         cout &lt;&lt; &quot;\\n&quot;;                  \/\/ \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u043c \u043f\u0430\u043c\u044f\u0442\u044c         delete x;     }      \/\/ \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 i \u0432 R     int ia[6] = { 1, 4, 6, 3, 5 , 2 };     Rinteger *ri = new Rinteger(ia, 6);     rc-&gt;assign(&quot;i&quot;, ri);     delete ri;      \/\/ \u0418\u0440\u0438\u0441\u044b \u0424\u0438\u0448\u0435\u0440\u0430 \u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438,      \/\/ \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0420\u043e\u043d\u0430\u043b\u044c\u0434 \u0424\u0438\u0448\u0435\u0440 \u0432 1936 \u0433\u043e\u0434\u0443 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b     \/\/ \u0440\u0430\u0431\u043e\u0442\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u0438\u0441\u043a\u0440\u0438\u043c\u0438\u043d\u0430\u043d\u0442\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430.     \/\/ \u042d\u0442\u043e\u0442 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u0432 R, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0435\u0433\u043e     Rvector *iris = (Rvector*) rc-&gt;eval(&quot;data(iris); iris&quot;);     if (!iris) {         cout &lt;&lt; &quot;oops! couldn't get iris data\\n&quot;; delete rc; return 0;     }      \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0431\u0435\u0440\u0435\u043c \u0448\u0438\u0440\u0438\u043d\u0443 \u0447\u0430\u0448\u0435\u043b\u0438\u0441\u0442\u0438\u043a\u043e\u0432 (sepal width) -     \/\/ \u0434\u0435\u0448\u0435\u0432\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a Rserve, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435     Rdouble *sw = (Rdouble*) iris-&gt;byName(&quot;Sepal.Width&quot;);     double *swd = sw-&gt;doubleArray();          \/\/ and print it ...     {          int i=0, ct=sw-&gt;length();          while (i&lt;ct) {             cout &lt;&lt; swd[i++] &lt;&lt; &quot; &quot;;         }         cout &lt;&lt; &quot;\\n&quot;;      }          \/\/ \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043c\u044f\u0442\u044c, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u043e\u0434 iris,     \/\/ \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 sw \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.     delete iris;          \/\/ \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f. \u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u043e\u0440\u0432\u0430\u043d\u043e.     delete rc; } <\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u043d\u0430\u0441\u0447\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e: \u0432\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c Rmessage, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u044f\u0432\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u00abeval\u00bb. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0438\u043a\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f Rexp, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 eval&#8217;\u043e\u043c (\u043d\u0430\u0437\u043e\u0432\u0451\u043c \u0435\u0433\u043e \u0433\u043b\u0430\u0432\u043d\u044b\u043c). \u041d\u0435\u043b\u044c\u0437\u044f \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0442\u044c \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 Rexp, \u043a\u0440\u043e\u043c\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e! \u041b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 Rexp, \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441 \u0433\u043b\u0430\u0432\u043d\u044b\u043c, \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0441\u043b\u0435 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e Rexp. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e Rexp \u043d\u0435\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c doubleArray()).<\/p>\n<p>  \u0421\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c  <\/p>\n<pre><code class=\"bash\"># g++ -c Rconnection.cc # g++ Rconnection.o main.cpp -o RExample -lcrypt <\/code><\/pre>\n<p>  \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c  <\/p>\n<pre><code class=\"bash\"># .\/RExample Rdouble[4] 2 by 2 matrix 33.97 -2.1 -2.1 10.09  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 3.7 3.4 3 3 4 4.4 3.9 3.5 3.8 3.8 3.4 3.7 3.6 3.3 3.4 3 3.4 3.5 3.4 3.2 3.1 3.4 4.1 4.2 3.1 3.2 3.5 3.6 3 3.4 3.5 2.3 3.2 3.5 3.8 3 3.8 3.2 3.7 3.3 3.2 3.2 3.1 2.3 2.8 2.8 3.3 2.4 2.9 2.7 2 3 2.2 2.9 2.9 3.1 3 2.7 2.2 2.5 3.2 2.8 2.5 2.8 2.9 3 2.8 3 2.9 2.6 2.4 2.4 2.7 2.7 3 3.4 3.1 2.3 3 2.5 2.6 3 2.6 2.3 2.7 3 2.9 2.9 2.5 2.8 3.3 2.7 3 2.9 3 3 2.5 2.9 2.5 3.6 3.2 2.7 3 2.5 2.8 3.2 3 3.8 2.6 2.2 3.2 2.8 2.8 2.7 3.3 3.2 2.8 3 2.8 3 2.8 3.8 2.8 2.8 2.6 3 3.4 3.1 3 3.1 3.1 3.1 2.7 3.2 3.3 3 2.5 3 3.4 3  <\/code><\/pre>\n<p>  \u0413\u043e\u0442\u043e\u0432\u043e! \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e\u0431 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 R \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c, \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0432 Rconnection.h. <\/p>\n<h4>Rserve.conf<\/h4>\n<p>  \u0421\u043a\u0430\u0436\u0443 \u043f\u0430\u0440\u0443 \u0441\u043b\u043e\u0432 \u043e \u0444\u0430\u0439\u043b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439 Rserve.conf. \u041e\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 R \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 Rserve. \u0424\u0430\u0439\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u0449\u0435\u0442\u0441\u044f \u0432 \/etc\/Rserve.conf, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0443\u0442\u044c, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0444\u043b\u0430\u0433\u043e\u043c &#8212;RS-conf \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 Rserve. Rserve.conf \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0446\u0438\u0438:<\/p>\n<p>  <code> workdir &lt;path&gt; [\/tmp\/Rserv] <\/code><br \/>  <code> pwdfile &lt;file&gt; [none=disabled] <\/code><br \/>  <code>remote enable|disable [disable]<\/code><br \/>  <code>auth required|disable [disable]<\/code><br \/>  <code>plaintext enable|disable [disable]<\/code><br \/>  <code>fileio enable|disable [enable]<\/code><br \/>  <code>interactive yes|no [yes] (since 0.6-2)<\/code><\/p>\n<p>  (\u0441 \u0432\u0435\u0440\u0441\u0438\u0438 0.1-9):<br \/>  <code>socket &lt;socket&gt; [none=disabled]<\/code><br \/>  <code>port &lt;port&gt; [6311]<\/code><br \/>  <code>maxinbuf &lt;size in kb&gt; [262144]<\/code><\/p>\n<p>  (\u0441 \u0432\u0435\u0440\u0441\u0438\u0438 0.3):<br \/>  <code>maxsendbuf &lt;size in kb&gt; [0=unlimited]<\/code><br \/>  <code>uid &lt;uid&gt; [none]<\/code><br \/>  <code>gid &lt;gid&gt; [none]<\/code><br \/>  <code>su now|server|client [none] (since 0.6-1)<\/code><\/p>\n<p>  (\u0441 \u0432\u0435\u0440\u0441\u0438\u0438 0.3-16):<br \/>  <code>source &lt;file&gt;<\/code><br \/>  <code>eval &lt;expressions&gt;<\/code><\/p>\n<p>  (\u0441 \u0432\u0435\u0440\u0441\u0438\u0438 0.5 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 unix):<br \/>  <code>chroot &lt;directory&gt; [none]<\/code><br \/>  <code>sockmod &lt;mode&gt; [0=default]<\/code><br \/>  <code>umask &lt;mask&gt; [0]<\/code><\/p>\n<p>  (\u0441 \u0432\u0435\u0440\u0441\u0438\u0438 0.5-3):<br \/>  <code>encoding native|utf8|latin1 [native]<\/code><\/p>\n<p>  \u041f\u0430\u043a\u0435\u0442\u0443 Rserve \u0438 C++ \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0443\u0436\u0435 \u043c\u043d\u043e\u0433\u043e \u043b\u0435\u0442, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0440\u0443\u0441\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u044b\u0445 \u043c\u0430\u043d\u0443\u0430\u043b\u043e\u0432 \u043f\u043e \u043d\u0438\u043c \u044f \u043d\u0435 \u043d\u0430\u0448\u0451\u043b. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u043a\u043e\u043c\u0443-\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<p>  P.S. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 load-balancer \u0434\u043b\u044f Rserve: <a href=\"https:\/\/www.rforge.net\/RSproxy\/\">RSproxy<\/a>.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/198012\/\"> http:\/\/habrahabr.ru\/post\/198012\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<i>R \u2014 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u0430\u044f \u0441\u0440\u0435\u0434\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 GNU \u00a9 Wikipedia. <\/i><\/p>\n<p>  \u0412 R \u0441\u043e\u0431\u0440\u0430\u043d\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043d\u0430 \u0432\u0441\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0436\u0438\u0437\u043d\u0438 \u0438 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u0440\u043e\u0434\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u044b: \u0435\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u044b, \u043a\u0430\u043a SPSS, Statistica, SAS, Wolfram Mathematica \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435. \u041a\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c R \u0432 \u0441\u0432\u043e\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f?<br \/>  \u041d\u0430 \u0445\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b\u0430 <a href=\"http:\/\/habrahabr.ru\/post\/161983\/\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043f\u0440\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 R \u0432 \u0421++, \u043e\u0434\u043d\u0430\u043a\u043e \u043e\u043d\u0430 \u043e\u0441\u0432\u0435\u0442\u0438\u043b\u0430 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u0448 \u043a\u043e\u0434 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434 GPL-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0439 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0435\u0439. \u041d\u043e \u0438 \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u0442\u044c \u0432\u044b\u0445\u043e\u0434 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u0430 Rserve.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-198012","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/198012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=198012"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/198012\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=198012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=198012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=198012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}