Skip to content
Prev 7193 / 10988 Next

[Rcpp-devel] conditionally created vectors

The way around it is to declare 'xx' in the parent scope, and then assign
to it directly, e.g.

// [[Rcpp::export]]
Rcpp::NumericVector f1(String typ){
  Rcpp::NumericVector xx;
  if(typ=="nc"){
    xx = Rcpp::NumericVector(10);
  } else {
    xx = Rcpp::NumericVector(20);
  }
  return xx;
}

'Technically', the object 'xx' will be default initialized when declared
like that, but the compiler can optimize that away.

Cheers,
Kevin


On Thu, Feb 13, 2014 at 10:26 AM, Hideyoshi Maeda <hideyoshi.maeda at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140213/f6462d72/attachment-0001.html>