Hi all,

I'm evaluating RInside/Rcpp to interact our C++ project with R.
I've seen the samples to get/set data (matrix, dataframes, etc) to/from R and 
it builds/works fine.
(Using gcc/mingw compiler from RTools on Windows)

My questions is about functions...
My project is C++, and it uses RInside to call R from our code.
Let's say I have a C++ function implemented in my project, and I want to pass 
that c++ function to R so it can be "used" as a R function (typically passed as 
argument to optim/optimize)
I couldn't find a way to do that using RInside.

Ideally, I'd like to achieve something like:

#include <RInside.h>

double Banana(double x, double y)
{
return (1-x)*(1-x)+100*(y-x*x)*(y-x*x);
}

Int main()
{
RInside R(argc,, argv);
R["fn"] = Banana;
R.parseEval("optim(c(-2,-2), fn");
}

I believe it's similar to 
https://stackoverflow.com/questions/53729493/rinside-wrapping-a-c-function-for-use-in-an-r-function
But I can't really understand the Rcpp::XPtr suggestion from Dirk.
Any help or pointers welcome :)
Thx a mil
[cid:image005.jpg@01D59593.3FF9BC00]<https://addactis.letsignit.com/r/32/6de77c22-c065-4906-899e-eec38189d60a/undefined>

[cid:image006.png@01D59593.3FF9BC00]<https://addactis.letsignit.com/r/199/c042c4a7-2508-4bf6-801a-4eeb09778ade/undefined>
  [cid:image007.png@01D59593.3FF9BC00] 
<https://addactis.letsignit.com/r/42/b8791eba-0dab-4aa1-ab9d-813a5f8be48d/undefined>
   [cid:image008.png@01D59593.3FF9BC00] 
<https://addactis.letsignit.com/r/45/15ea361f-f441-4b13-94a0-4bdb30820d9a/undefined>


   William LEVRA-JUILLET
   Senior Software Architect
   ADDACTIS Software
   +33 (0)4 81 92 13 00


   
www.addactis.com<https://addactis.letsignit.com/r/32/91871b88-8586-4561-b012-50a3a792527a/undefined>






[cid:image009.jpg@01D59624.80111590]<https://addactis.letsignit.com/r/32/cf8ac9eb-d46f-4524-bc9e-5cdb532bef11/undefined>

[cid:image010.png@01D59624.80111590]<https://addactis.letsignit.com/r/199/49e483e9-091d-4caf-a1b4-7e37d9c9ac9e/undefined>
  [cid:image011.png@01D59624.80111590] 
<https://addactis.letsignit.com/r/42/72f7499f-cd02-4bd4-835a-88f1053cabf2/undefined>
   [cid:image012.png@01D59624.80111590] 
<https://addactis.letsignit.com/r/45/b9ce1c50-1455-48cb-b90f-b8348d799476/undefined>


   William LEVRA-JUILLET
   Senior Software Architect
   ADDACTIS Software
   +33 (0)4 81 92 13 00


   
www.addactis.com<https://addactis.letsignit.com/r/32/9cd210c2-e7cd-4d30-995a-e3ba4da16780/undefined>





_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to