<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Dirk,</div><div><br></div><div>Maybe I didn't explain it well enough. The question absolutely pertains to using the inline functionality.</div><div><br></div><div>As each new data arrives, I want to pass it to my C++ function. If this were a pure C++ implementation, then I would just append an STL vector and pass a pointer of that vector to the function. However, since this is R, I don't see how to do that. I can, of course, keep a vector in R and pass the entire vector to the C++ function. That will, however slow things down significantly.</div><div><br></div><div>Ultimately, I'dl like to have R pass each new data point to the C++ function, and have that function manage keeping the appropriate length window of past data points. (Again, trivial to do in pure C++).</div><div><br></div><div>This really is an issue of persistent object and passing between R and C++. I want a persistent C++ vector, not an R data structure. (Having C++ manage the vector will be much faster.)</div><div><br></div><div><br></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>--</div><div>Noah Silverman</div><div>UCLA Department of Statistics</div><div>8117 Math Sciences Building #8208</div><div>Los Angeles, CA 90095</div></div></div></span></div></span></div></span></div></span></span>
</div>
<br><div><div>On Sep 7, 2011, at 2:56 PM, Dirk Eddelbuettel wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>On 7 September 2011 at 14:46, Noah Silverman wrote:<br>| Hi,<br>| <br>| <br>| I'm writing a function using Rcpp through inline. This function will be a<br>| filter on an incoming data stream. <br>| <br>| I need to keep the past several data values so that they are accessible to the<br>| function each time it is called. This is easy to do with a data structure in<br>| R (and then passing subsequent structure to the C++ function) but that seems<br>| rather slow. Is there some way to define a persistent object that is<br>| accessible to an Inline function using Rcpp?<br>| <br>| <br>| If the code was in pure C++, it would be trivial to have an object and then<br>| just pass a pointer to that object. I can't figure out how to do the same<br>| thing with R+Rcpp+inline.<br><br>i) Read up on the 'static' argument for variable declarations in C and C++.<br><br>ii) Rethink your architecture, maybe have an 'agent' operate on the stream<br> and report to a persisting 'broker' that keeps state.<br><br>iii) Read up on persisting data as a general issue.<br><br><br>This has little to do with Rcpp and your preference of inline over packages,<br>but rather with how to think in code (and/or C++) and that is NOT a topic<br>covered on this list. <br><br>Let's please try to keep focus on Rcpp and related questions here.<br><br>Dirk<br><br><br>| Thanks!<br>| <br>| --<br>| Noah Silverman<br>| UCLA Department of Statistics<br>| 8117 Math Sciences Building #8208<br>| Los Angeles, CA 90095<br>| <br>| <br>| ----------------------------------------------------------------------<br>| _______________________________________________<br>| Rcpp-devel mailing list<br>| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>-- <br>Two new Rcpp master classes for R and C++ integration scheduled for <br>New York (Sep 24) and San Francisco (Oct 8), more details are at<br><a href="http://dirk.eddelbuettel.com/blog/2011/08/04#rcpp_classes_2011-09_and_2011-10">http://dirk.eddelbuettel.com/blog/2011/08/04#rcpp_classes_2011-09_and_2011-10</a><br>http://www.revolutionanalytics.com/products/training/public/rcpp-master-class.php<br></div></blockquote></div><br></body></html>