[R] how to add 1 + 1 with the interface between R and C
Cleber N.Borges
klebyn at yahoo.com.br
Mon Sep 21 04:03:35 CEST 2015
Dear useRs,
I would like some help on how to make the sum of 1 + 1
but using the interface between A and C.
the function call does .call lock and close the R.
Thank you for any help it.
Cleber
#######################
############ R code
text_code <-"
#include <stdlib.h>
#include <R.h>
#include <Rdefines.h>
void testfun( double *k, double *res );
void testfun( double *k, double *res )
{
res = k + 1;
}
"
sink('test.c')
cat( text_code )
sink()
system("R CMD SHLIB test.c")
dyn.load( "test.dll" )
is.loaded( 'testfun' )
k=1
.C('testfun', k=as.double(k), res=as.double(0) )
####################################
### Output
> text_code <-"
+ #include <stdlib.h>
+ #include <R.h>
+ #include <Rdefines.h>
+ void testfun( double *k, double *res );
+ void testfun( double *k, double *res )
+ {
+ res = k + 1;
+ }
+ "
> sink('test.c')
> cat( text_code )
> sink()
> system("R CMD SHLIB test.c")
cygwin warning:
MS-DOS style path detected: C:/R/etc/x64/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/R/etc/x64/Makeconf
CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gcc -m64 -I"C:/R/include" -DNDEBUG
-I"d:/RCompile/r-compiling/local/local320/include" -O2 -Wall
-std=gnu99 -mtune=core2 -c test.c -o test.o
gcc -m64 -shared -s -static-libgcc -o test.dll tmp.def test.o
-Ld:/RCompile/r-compiling/local/local320/lib/x64
-Ld:/RCompile/r-compiling/local/local320/lib -LC:/R/bin/x64 -lR
>
> dyn.load( "test.dll" )
>
> is.loaded( 'testfun' )
[1] TRUE
> k=1
> .C('testfun', k=as.double(k), res=as.double(0) )
$k
[1] 1
$res
[1] 0
---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus
More information about the R-help
mailing list