[R] How can I use R:sort function in C code?
cls59
chuck at sharpsteen.net
Tue Sep 15 16:51:53 CEST 2009
Guozhu.Wen wrote:
>
> Hi, I wrote a C extension for R. Within the C code I wanted to invoke the
> R's sort function, with the argument "index.return = TRUE". I found it is
> a
> difficult problem, how can I do that? I have implemented the decreasing
> sorting by the code "PROTECT(R_fcall = lang3(install("sort"), x, desc));",
> but how to define the "index.return" argument?
>
> Thanks in advanced!
>
> --
> Guozhu. Wen
>
>
I found this a little tricky to do the first time-- but it's not bad at all
once you go through it. The steps I usually follow are:
1. Create an object to hold your function call.
2. Find the R function you want to call.
3. Prepare the function call by setting attributes on your object.
4. Execute the function call.
5. Recover data.
Unfortunately, I have to run to a meeting this morning so I can't write out
examples of all these steps. I suggest looking at section 5.11 of the
"Writing R Extensions" manual. Also, section 10.2 of the tikzDevice vignette
details an example of calling an R function from within a C function.
Good luck!
-Charlie
-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
--
View this message in context: http://www.nabble.com/How-can-I-use-R%3Asort-function-in-C-code--tp25450683p25455479.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list