[R] Problem with .C
Steve Lianoglou
mailinglist.honeypot at gmail.com
Thu Oct 6 15:41:01 CEST 2011
Hi,
2011/10/6 Uwe Ligges <ligges at statistik.tu-dortmund.de>:
> On 06.10.2011 14:51, Jan van der Laan wrote:
>>
>> An obvious reason might be that your second argument should be a pointer
>> to int.
>>
>> As others have mentioned, you might want to have a look at Rccp and/or
>> inline. The documentation is good and I find it much easier to work with.
>>
>> For example, your example could be written as:
>>
>> library(Rcpp)
>> library(inline)
>>
>> test <- cxxfunction(signature(x = "numeric" ) , '
>> Rcpp::NumericVector v(x);
>> Rcpp::NumericVector result(v.length());
>> for (int i = 0; i < v.length(); ++i) {
>> result[i] = v[i] + i;
>> }
>> return(result);
>> ', plugin = "Rcpp" )
>>
>
>
> Oh, come on, this is now really too much of overkill.
I don't agree that it's overkill -- you get to sidestep the whole `R
CMD SHLIB ...` and `dyn.load` dance this way while you experiment with
C(++) code 'live" using the inline package.
It's really handy.
> Just make the original source
>
>
> void test(double *b, int *l)
> {
> int i;
> for(i=0; i < *l ; i++) b[i] += i;
> }
>
>
> which you would have know after reading the Wriiting R Extensions manual.
I agree that this step is unavoidable no matter which avenue (Rcpp or
otherwise) one decides to take.
-steve
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the R-help
mailing list