########## R function: sumRecipsViaCppNest #########
# For obtaining the sum of the reciprocals
# of the first "n" integers. This version
# uses Rcpp and C++.
# In this version there is a user-written
# function named "myRecip" nested inside
# the reciprocals summing function.
# Last changed: 08 OCT 2019
cppFunction("double sumRecipsViaCppNest(int n, Function myRecipPure)
{
double total = 0;
double currRecip;
/* Now add the first n reciprocals: */
for (int i = 1 ; i <= n; ++i)
{
currRecip = myRecipPure(i);
total += currRecip;
}
return total;
}")
############ End of sumRecipsViaCppNest #########