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

Jingyu He jingyu.he at chicagobooth.edu
Fri Nov 11 06:16:23 CET 2016


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 <Rcpp.h>using namespace Rcpp;// [[Rcpp::export]]RObject
callWithOne(Function f) {
  return f(1);}

The question is, how to set the default value for f? I would like to have
the choice to pass a function or not, like

callWithOne(Function f = NULL) {
  // if pass f, run f(1)
  // else, run something else}


Jingyu He
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20161111/c7e5cd13/attachment.html>

More information about the Rcpp-devel mailing list