Re: [Rcpp-devel] How to set a default value when call a R function in Rcpp

2016-11-11 Thread Jingyu He
It works, thanks a lot! Qiang Kou 于2016年11月11日 周五09:07写道: > Hi, Jingyu, > > I post a small example below. I think this is what you want. > > Best, > > KK > > #include > > using namespace Rcpp; > > //[[Rcpp::export]] > void test(Nullable f = R_NilValue) { > if (f.isNotNull()) { > Rcpp::Rcout

Re: [Rcpp-devel] How to set a default value when call a R function in Rcpp

2016-11-11 Thread Qiang Kou
Hi, Jingyu, I post a small example below. I think this is what you want. Best, KK #include using namespace Rcpp; //[[Rcpp::export]] void test(Nullable f = R_NilValue) { if (f.isNotNull()) { Rcpp::Rcout << "Not NULL fun" << std::endl; Function f2(f); f2(); } else { Rcout <

Re: [Rcpp-devel] How to set a default value when call a R function in Rcpp

2016-11-11 Thread Dirk Eddelbuettel
On 11 November 2016 at 05:53, Jingyu He wrote: | I've deleted the post on StackOverflow. Sorry for the ambiguity, the problem is | not arg, but the Function f.  | | | #include | using namespace Rcpp; | // [[Rcpp::export]] | RObject cppfunction(Function rfunction = NULL) { |       if( rfunction

Re: [Rcpp-devel] How to set a default value when call a R function in Rcpp

2016-11-10 Thread Jingyu He
Hi, I've deleted the post on StackOverflow. Sorry for the ambiguity, the problem is not arg, but the Function f. #include using namespace Rcpp; // [[Rcpp::export]] RObject cppfunction(Function rfunction = NULL) { if( rfunction == NULL){ cout << 1 + 1 << endl; // if we don't pass rf

Re: [Rcpp-devel] How to set a default value when call a R function in Rcpp

2016-11-10 Thread Dirk Eddelbuettel
On 11 November 2016 at 05:16, Jingyu He wrote: | I'm writing a R package by Rcpp and I have a problem when setting default value | when call a R function in Rcpp. Here is an example to pass a R function to C++, | provided by http://adv-r.had.co.nz/Rcpp.html | | #include | using namespace Rcpp;

[Rcpp-devel] How to set a default value when call a R function in Rcpp

2016-11-10 Thread Jingyu He
Hi, I'm writing a R package by Rcpp and I have a problem when setting default value when call a R function in Rcpp. Here is an example to pass a R function to C++, provided by http://adv-r.had.co.nz/Rcpp.html #include using namespace Rcpp;// [[Rcpp::export]]RObject callWithOne(Function f) { re