[R] question about "R get vector from C"

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu Apr 14 11:53:08 CEST 2005


Michael S wrote:
> Dear ALL-R helpers,
> 
> I want to let R get vector from c ,for example :numeric array ,vector .I 
> saw some exmple like this :
> /* useCall3.c                                    */
> /* Getting an integer vector from C using .Call  */
> #include <R.h>
> #include <Rdefines.h>
> 
> SEXP setInt() {
>   SEXP myint;
>   int *p_myint;
>   int len = 5;
>   PROTECT(myint = NEW_INTEGER(len));  // Allocating storage space
>   p_myint = INTEGER_POINTER(myint);
>   p_myint[0] = 7;
>   UNPROTECT(1);
>   return myint;
> }
> 
> then type at the command prompt:
> R CMD SHLIB useCall3.c
> to get useCall3.so
> In windows platform ,how can I create right dll to let dyn.load use
> and for .c ,.call ,external ,what are the differece? which one is better 
> for  getting vector from C?


For the code above you certainly want to use .Call(), .C() and won't 
work with SEXP.
Under Windows, you can also say
   R CMD SHLIB useCall3.c
and get the corresponding useCall3.dll instead of useCall3.so. 
dyn.load() also works as expected, you just need the relevant tools / 
compiler installed.

Uwe Ligges


> thanks in advance
> 
> Michael
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list