Hello again,
I hope I don't disturb you too much. I have again a small question. I haven't seen the answer on your vignette, maybe this is not possible. Here's what I would like to do :
double Foo(double x, double a1, double a2) {
return f(x,a1,a2);
}
NumericVector myVec;
sapply(myVec, Foo( ??, a1, a2)); // This is the line not working
In every example I saw, Foo (in the example, it's sometimes square) could only have one parameter (and in my case I have many parameters).
Is it possible ? Am I missing something ?
Thank you very much (again) for your time,
Have a nice evening/week-end,
Julien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130510/9e71d3ed/attachment.html>
[Rcpp-devel] [RCPP Sugar] sapply function
4 messages · Romain Francois, Julien Duvanel
Iirc we have mapply2 and mapply3. Otherwise you can make Foo a helper class instead of a function. And you embed the 3 variables in your class. Le 10 mai 2013 ? 17:40, Julien Duvanel <julien.duvanel at epfl.ch> a ?crit :
Hello again,
I hope I don't disturb you too much. I have again a small question. I haven't seen the answer on your vignette, maybe this is not possible. Here's what I would like to do :
double Foo(double x, double a1, double a2) {
return f(x,a1,a2);
}
NumericVector myVec;
sapply(myVec, Foo( ??, a1, a2)); // This is the line not working
In every example I saw, Foo (in the example, it's sometimes square) could only have one parameter (and in my case I have many parameters).
Is it possible ? Am I missing something ?
Thank you very much (again) for your time,
Have a nice evening/week-end,
Julien
_______________________________________________ Rcpp-devel mailing list Rcpp-devel at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130510/a6f933b2/attachment.html>
Hello, Thanks for you quick answer (again!). After some research, I found the functions : Mapply_2, and Mapply_3. I'll have a look how it works. I haven't understood the second proposition but if the first one works it's fine. Have a nice evening, J. Le vendredi, 10 mai 2013 ? 17:47, Romain Francois a ?crit :
Iirc we have mapply2 and mapply3. Otherwise you can make Foo a helper class instead of a function. And you embed the 3 variables in your class. Le 10 mai 2013 ? 17:40, Julien Duvanel <julien.duvanel at epfl.ch (mailto:julien.duvanel at epfl.ch)> a ?crit :
Hello again,
I hope I don't disturb you too much. I have again a small question. I haven't seen the answer on your vignette, maybe this is not possible. Here's what I would like to do :
double Foo(double x, double a1, double a2) {
return f(x,a1,a2);
}
NumericVector myVec;
sapply(myVec, Foo( ??, a1, a2)); // This is the line not working
In every example I saw, Foo (in the example, it's sometimes square) could only have one parameter (and in my case I have many parameters).
Is it possible ? Am I missing something ?
Thank you very much (again) for your time,
Have a nice evening/week-end,
Julien
_______________________________________________ Rcpp-devel mailing list Rcpp-devel at lists.r-forge.r-project.org (mailto:Rcpp-devel at lists.r-forge.r-project.org) https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130510/ed9ba40e/attachment.html>
20 days later
Le 10/05/13 17:40, Julien Duvanel a ?crit :
Hello again,
I hope I don't disturb you too much. I have again a small question. I
haven't seen the answer on your vignette, maybe this is not possible.
Here's what I would like to do :
/double Foo(double x, double a1, double a2) {/
/return f(x,a1,a2);/
/}/
/
/
/NumericVector myVec;/
/
/
/sapply(myVec, Foo( ??, a1, a2)); // This is the line not working/
In every example I saw, Foo (in the example, it's sometimes square)
could only have one parameter (and in my case I have many parameters).
Is it possible ? Am I missing something ?
Thank you very much (again) for your time,
Have a nice evening/week-end,
Julien
So to elaborate on my answer, since you did not report back, something
like this works for me:
#include <Rcpp.h>
using namespace Rcpp ;
double fun(double x, double y, double z) {
return x + y + z ;
}
// [[Rcpp::export]]
NumericVector mapply_fun(NumericVector x, NumericVector y, NumericVector z){
return mapply(x, y, z, fun ) ;
}
So mapply'ing fun over x, y and z. works for 2 or 3 objects for now.
Romain
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 R Graph Gallery: http://gallery.r-enthusiasts.com blog: http://blog.r-enthusiasts.com |- http://bit.ly/Zs97qg : highlight 0.4.1 `- http://bit.ly/10X94UM : Mobile version of the graph gallery