<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Hi Antonio, </div><div><br></div><div>This is about how R evaluation works. Might not just be what you think it is. </div><div><br></div><div>When you use Rcpp and therefore .Call things are evaluated fairly early, at least earlier than what would happen with R, etc … you can reproduce what R does by using promises. For example this work in Rcpp11: </div><div><br></div><div><div>// [[Rcpp::export]]</div><div>RawVector rcpp_serialize(Dots dots){</div><div>  Function serialize("serialize") ;</div><div>  return serialize( dots.promise(0), R_NilValue ) ;</div><div>}</div></div><div><br></div><div>Dots has not been implemented in Rcpp, but would not be too hard to port: </div><div><a href="https://github.com/romainfrancois/Rcpp11/blob/master/inst/include/Rcpp/Dots.h">https://github.com/romainfrancois/Rcpp11/blob/master/inst/include/Rcpp/Dots.h</a></div><div><br></div><div>But it would also need to fix Rcpp’s handling of recursive promises (i.e. promise of a promise of a promise). </div><div><br></div><div><br></div><div><br></div><div>Alternatively, for a solution based on Rcpp, you can look in dplyr. The .data_dots function has most of the R-level logic</div><div><a href="https://github.com/hadley/dplyr/blob/master/R/manip-df.r">https://github.com/hadley/dplyr/blob/master/R/manip-df.r</a></div><div><br></div><div>And the C++ logic is mostly in DataDots.h</div><div><a href="https://github.com/hadley/dplyr/blob/master/inst/include/tools/DataDots.h">https://github.com/hadley/dplyr/blob/master/inst/include/tools/DataDots.h</a></div><div><br></div><div>Romain</div><div><br></div><div><div>Le 6 févr. 2014 à 02:07, Antonio Piccolboni <<a href="mailto:antonio@piccolboni.info">antonio@piccolboni.info</a>> a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hi,<div>I was wondering why I can serialize a call such as in</div><div><br></div><div>serialize(call("ripley"), NULL) </div><div><div>[1] 58 0a 00 00 00 02 00 03 00 02 00 02 03 00 00 00 00 06 00 00 00 01 00 04 00 09 00 00 00 06 72 69 70 6c 65 79 00 00 00 fe</div>


</div><div><br></div><div>but if I try from C++ the call gets evaluated</div><div><br></div><div> library("Rcpp")<br></div><div><div><br></div><div> rcpp.serialize = cppFunction(code="RObject my_serialize(RObject x){Function r_serialize(\"serialize\"); return r_serialize(x, R_NilValue);}")<br>


</div><div><br></div><div> rcpp.serialize(10)</div><div> [1] 58 0a 00 00 00 02 00 03 00 02 00 02 03 00 00 00 00 0e 00 00 00 01 40 24 00 00 00 00 00 00</div><div># easy things work</div><div><br></div><div> rcpp.serialize(call("ripley"))</div>


<div>Error: could not find function "ripley"</div><div># wants to evaluate it</div><div><br></div><div> unserialize(rcpp.serialize(call("sqrt", 2)))<br></div><div>[1] 1.414214</div><div># How is one to serialize the call itself</div>


<div><br></div><div> rcpp.serialize(list(call("ripley")))</div><div> [1] 58 0a 00 00 00 02 00 03 00 02 00 02 03 00 00 00 00 13 00 00 00 01 00 00 00 06 00 00 00 01 00 04 00 09 00 00 00 06 72 69 70 6c 65 79 00 00 00 fe</div>


</div><div>#wrapping in a list is enough to stop evaluation</div><div><br></div><div><div> eval(call("ripley"))</div><div>Error in eval(expr, envir, enclos) : could not find function "ripley"</div><div>


 eval(list(call("ripley")))</div><div>[[1]]</div><div>ripley()</div></div><div><br></div><div>#OK that's consistent</div><div><br></div><div><br></div><div>Could anyone enlighten me on the evaluation mechanism? Not saying it's broken, but certainly my expectations were off. Thanks</div>


<div><br></div><div><br></div><div>Antonio</div></div>
_______________________________________________<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>https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</blockquote></div><br></body></html>