[R] C function call in R
Dan Davison
davison at stats.ox.ac.uk
Tue May 18 20:33:32 CEST 2010
John Lande <john.lande77 at gmail.com> writes:
> dear all,
>
> we am trying to improve the performance of my R code, with the implentation
> of some function with custom C code.
> we found difficult to import and export/import data structure such us
> matrices or data.frame into the external C functions.
Please give a *very simple* example of what you're trying and failing to
do.
Use the .C() interface, forget about the .Call interface. Then it is not
that hard. Start with the convolve example on p.69 and 70 of Writing R
Extensions. Get that working and then turn it into your problem.
Forget about lists and data frames: everything is going to be a simple
vector. That includes arrays and matrices: you can pass them in, but C
will know nothing about their dimensions until you tell it. Of course,
you can pass the dimension vectors in as a separate vector. So, if you
use arrays, you need to understand the order in which R stores the
elements of the array. If your problem cannot be solved with the .C
interface then you should consider whether it is worthwhile to proceed
as the .Call interface repays those who use it frequently but has a
considerably steeper learning (and forgetting) curve.
Dan
>
> we already tried the solution from "Writing R Extensions" form the R
> webpage.
>
> do you have any other solution or more advanced documentation on that point?
>
> looking forward your answer
>
> [[alternative HTML version deleted]]
More information about the R-help
mailing list