<div dir="ltr">Dear Dirk and JJ,<div><br></div><div> thank you very much for your replies. In the end a named vector is</div><div>enough for my purpose:</div><div><br></div><div><div>cppFunction(</div><div>  '</div><div>
  NumericVector myVett(NumericVector x = NumericVector::create(0) )</div><div> {</div><div>  if(x.size() == 0) x = NumericVector::create(_["a"] = 1.0, _["b"] = 2.0);</div><div>  return x;</div><div> }</div>
<div> ' </div><div>)</div><div><br></div><div>myVett()</div></div><div><span class="" style="border-collapse:separate;color:rgb(0,0,0);font-family:'Ubuntu Mono';font-size:14px;line-height:16px;white-space:pre-wrap;border-spacing:0px;background-color:rgb(225,226,229)"><pre tabindex="0" class="" style="font-family:'Ubuntu Mono';outline:none;border:none;margin-top:0px;margin-bottom:0px;line-height:1.2;font-size:10.4pt!important;white-space:pre-wrap!important">
a b 
1 2</pre></span></div><div><br></div><div><br></div><div>Thanks,</div><div><br></div><div>Matteo</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 14, 2013 at 2:41 PM, JJ Allaire <span dir="ltr"><<a href="mailto:jj.allaire@gmail.com" target="_blank">jj.allaire@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font face="arial,helvetica,sans-serif">Hi Matteo,</font><div><font face="arial,helvetica,sans-serif"><br></font></div>
<div><font face="arial,helvetica,sans-serif">The issue here is that the Rcpp attributes code that parses function declarations isn't able to parse all syntactic forms of C++ but rather a subset. The default argument parsing is able to handle scalars, strings, and simple vector initializations but not more complex expressions like the one in your example. The warning you get is saying that the default argument couldn't be parsed as a result of these limitations. The lack of a default argument definition is then what caused the subsequent error.</font></div>

<div><font face="arial,helvetica,sans-serif"><br></font></div><div><font face="arial,helvetica,sans-serif">Best,</font></div><div><font face="arial,helvetica,sans-serif"><br></font></div><div><font face="arial,helvetica,sans-serif">J.J.<br>

</font><br><div class="gmail_quote"><div><div class="h5">On Wed, Aug 14, 2013 at 3:42 AM, Matteo Fasiolo <span dir="ltr"><<a href="mailto:matteo.fasiolo@gmail.com" target="_blank">matteo.fasiolo@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
<div dir="ltr">Dear Rcpp users,<div><br></div><div> a very simple question: I have a function that has a Rcpp::List</div><div>among its arguments, and I would like to set a default values for</div><div>that List.</div><div>


Unfortunately this code:</div><div><br></div><div><div>cppFunction(</div><div>  '</div><div>  List myList(List x = List::create(_["a"] = 1, _["b"] = 2))</div><div> {</div><div>  return x;</div><div>


 }</div><div> ' </div><div>)</div><div><br></div></div><div>raises the warning:</div><div><br></div><div><span style="border-collapse:separate;border-spacing:0px;background-color:rgb(225,226,229)"><pre style="outline:none;border:none;margin-top:0px;margin-bottom:0px">
<span style="border-collapse:separate;border-spacing:0px"><pre style="outline:none;border:none;margin-top:0px;margin-bottom:0px"><span style="color:rgb(197,6,11);font-family:'Ubuntu Mono';font-size:10.4pt!important;line-height:1.2;white-space:pre-wrap!important">Warning message:
</span><span style="color:rgb(197,6,11);font-family:'Ubuntu Mono';font-size:10.4pt!important;line-height:1.2;white-space:pre-wrap!important">Unable to parse C++ default value 'List::create(_["a"] = 1, _["b"] = 2)' for argument x of function myList 
</span><span><font color="#0000ff" face="Ubuntu Mono"><span style="font-size:14px;line-height:16px">> 
> myList()</span></font><font color="#0000ff" face="Ubuntu Mono" size="3"><span style="line-height:1.2;white-space:pre-wrap!important">
</span></font></span><span style="color:rgb(197,6,11);font-family:'Ubuntu Mono';font-size:10.4pt!important;line-height:1.2;white-space:pre-wrap!important">Error in .Primitive(".Call")(<pointer: 0xb5907fb0>, x) : 'x' is missing</span></pre>


</span></pre></span></div><div><br></div><div>Similar code with NumericVector works fine:</div><div><br></div><div><div>cppFunction(</div><div>  '</div><div>  NumericVector myVett(NumericVector x = NumericVector::create(3))</div>


<div> {</div><div>  return x;</div><div> }</div><div> ' </div><div> )</div><div><br></div><div>myVett()</div></div><div><div># [1] 0 0 0</div><div><br></div><div>Am I doing something wrong? Thanks!</div></div></div>
<br></div></div><div class="im">_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">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" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></div></blockquote></div><br></div>
</blockquote></div><br></div>