[Rcpp-devel] conditionally created vectors

Dirk Eddelbuettel edd at debian.org
Thu Feb 13 19:33:39 CET 2014


On 13 February 2014 at 18:26, Hideyoshi Maeda wrote:
| So I’m guessing there is no simple export outside of the {} function?

Wrong. You can also do this, relying on the Rcpp vector constructor:

#include <Rcpp.h>

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


This is pretty basic C / C++ so you may want to go back and revisit some of
your books.

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list