[R] how to add 1 + 1 with the interface between R and C

Cleber Borges klebyn at yahoo.com.br
Mon Sep 21 19:56:32 CEST 2015


I think is time to learning Rcpp! :-)

thank you   (Peter Dalgaard and Dirk Eddelbuettel )  by the examples!

the more simples are often more informatives...

cleber

Em 21/09/2015 12:36, Dirk Eddelbuettel escreveu:
> peter dalgaard <pdalgd <at> gmail.com> writes:
>> C is call by value and k and res are pointers. You need a dereferencing
> step or nothing with happen. Try
>> *res = *k + 1;
> Or you use Rcpp which writes the glue code. Save the following into a file:
>
>
> #include <Rcpp.h>
>
> // [[Rcpp::export]]
> int adder(int x, int y) {
>    return x + y;
> }
>
> /*** R
> adder(40, 2)
> */
>
>
>
>
> Running this is as simple as sourcing it:
>
>    R> Rcpp::sourceCpp("/tmp/adder.cpp")
>
>    R> adder(40, 2)
>    [1] 42
>    R>
>
> and it even runs the R snippet at the bottom.
>
> Dirk
>
> ______________________________________________


---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus



More information about the R-help mailing list