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 <Rcpp.h> | using namespace Rcpp; | // [[Rcpp::export]] | RObject cppfunction(Function rfunction = NULL) { | if( rfunction == NULL){ | cout << 1 + 1 << endl; // if we don't pass rfunction to cppfunction, run | something not related to rfunction() | }else{ | rfunction() // if we pass rfunction to cppfunction, run it | } | } | | rfunction is an argument of cppfunction. Sometimes I need to pass rfunction to | cppfunction sometimes not. So I need to set a default rfunction (something like | NULL indicating not passing it). | | But | RObject cppfunction(Function rfunction = NULL) | doesn't work. How can I make it?
Well that is a different question :) But it has a nice answer: use Rcpp::Nullable<Rcpp::Function> rfunction and test via if (rfunction.isNull()) (Untested, but should work) Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel