<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#c0c0c0">
<pre wrap="">Thanks.
I did not understand this code
# C++ source code to operate on function and vector
cpp <- '
int n = as<int>(N);
NumericVector numvec(xvec) ;
Function f(fun) ;
for( int i=0; i<n; i++){
numvec = f( numvec ) ;
}
return numvec ;
I see that f is a Function object but what is fun? And why the looping over numvec rather than elements of numvec? Finally, how to use RcppArmadillo to do the C++ computations on the R function?
Best.
</pre>
<br>
<br>
On 1/25/2011 12:17 PM, Dirk Eddelbuettel wrote:
<blockquote cite="mid:19775.5040.107659.24030@max.nulle.part"
type="cite">
<pre wrap="">On 25 January 2011 at 12:01, Siddhartha Chib wrote:
| Is it possible to pass a user defined function
| written in R for use in rccparma. For example, is it possible to have a
(What is rccparma?)
| function
| SEXP myfunction(SEXP g, SEXP a)
| where g is a function object and a is a
| matrix, the argument of g?
Have you looked at
examples/functionCallback/newApiExample.r
which installed with your copy of Rcpp -- it uses Rcpp to sweep a
user-supplied R function over a vector. Doing this with a matrix is close.
And just for completeness, there is more in other place; my RcppDE riff on
the the DEoptim software allows you to pass objective functions as either R
or C++ functions; the C++ side then needs external pointers.
Hope this helps, Dirk
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Siddhartha Chib
Harry C. Hartkopf Professor of Econometrics and Statistics
Olin Business School, Campus Box 1133
Washington University in St. Louis
1 Brookings Dr
St. Louis, MO 63130
(314) 935-4657; (314) 935-6359 [Fax]
<a class="moz-txt-link-abbreviated" href="mailto:chib@wustl.edu">chib@wustl.edu</a>
<a class="moz-txt-link-freetext" href="http://www.olin.wustl.edu/faculty/chib/">http://www.olin.wustl.edu/faculty/chib/</a>
</pre>
</body>
</html>