[Rcpp-devel] Fwd: Looping over the parameters of a function

Hao Ye hye at ucsd.edu
Tue Apr 8 17:52:17 CEST 2014


Hi Petre,

It sounds like what you want is to curry a function f(x, a) into a function g(x) that will then get passed to your root-finder. See:
http://stackoverflow.com/questions/152005/how-can-currying-be-done-in-c

Best,
--
Hao Ye
hye at ucsd.edu

On Apr 8, 2014, at 8:36 AM, Petre Caraiani <petre.caraiani at gmail.com> wrote:

> 
> 
> 
> I don't know how to change the parameters of the function. The Brent routine finds the root of a function depending just on x. I know how to pass a vector between R and C, but I want to pass it to the function, while having the function depending on variable x only.
> 
> 
> On Tuesday, April 8, 2014, Dirk Eddelbuettel <edd at debian.org> wrote:
> 
> On 8 April 2014 at 16:41, Petre Caraiani wrote:
> | I have a code in C which computes the root of a function using the Brent
> | algorithm. The code is attached below. I provided the full code but you can
> | focus on the function definition and the main program. I can call this program
> | from R. What I am interested in is looping over the parameters of the defined
> | function. For example, passing an array a to the C program and computing the
> | root of the function: (x*x-a[i]/2) for each entry in vector a.
> 
> I don't follow. Excactly what is issue you are having?  How to pass a vector
> from R to C++ and back?  How to access elements in the vector?
> 
> You seem to have all relevant elements in place. Have a look at posted
> examples, eg on the Rcpp Gallery, or examples included in the Rcpp or other
> packages.
> 
> Dirk
> 
> --
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
> 
> _______________________________________________
> 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/20140408/9e580fcf/attachment-0001.html>


More information about the Rcpp-devel mailing list