[Rcpp-devel] How to put the code 2013-01-05-r-function-from-c++.cpp in the src/ directory of a package?
Dirk Eddelbuettel
edd at debian.org
Fri May 24 15:44:37 CEST 2013
On 24 May 2013 at 08:25, Peng Yu wrote:
| > Stick callFunction() in that package.
|
| I have read the documents that you mentioned and I'm able to put other
| functions in a package. The difference for "callFunction" is that it
| takes Function as an argument so I'm not able to get the code work in
| cxxfunction. Is there an exampling using cxxfunction (rather than the
| sourceCpp and cppFunction examples given by Xiao) for
| 2013-01-05-r-function-from-c++.cpp? Once I have a working example with
| cxxfunction, I then should be able to put it in a package.
Read the _basic_ Rcpp documentation and learn about the Function class. There
is nothing special here. Here is a basic example:
R> cppFunction('NumericVector applyFunction(Function f, NumericVector x) { return f(x); }')
R> applyFunction(log, 1:10)
[1] 0.000000 0.693147 1.098612 1.386294 1.609438 1.791759 1.945910 2.079442 2.197225 2.302585
R> applyFunction(sqrt, 1:10)
[1] 1.00000 1.41421 1.73205 2.00000 2.23607 2.44949 2.64575 2.82843 3.00000 3.16228
R>
Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list