[R-br] somar 1+1 mas com R e C

Benilton Carvalho beniltoncarvalho em gmail.com
Segunda Setembro 21 15:47:32 BRT 2015


se sua função retorna void, vc a chama via .C()

o seu código tbm deve ser corrigido para res[0] e k[0].

2015-09-20 21:54 GMT-03:00 Cleber N.Borges <klebyn em yahoo.com.br>:

> Prezados,
>
> Gostaria de uma ajuda em como fazer a soma de 1+1
> mas usando a interface entre R e C.
>
> a chamada da função  .Call faz travar e fechar o R.
>
> Agradeço por qualquer ajuda nisso
>
> Cleber
>
> # um CMR (do conceito) abaixo:
> ################################################
> > texto_code <-"
> + #include <stdlib.h>
> + #include <R.h>
> + #include <Rdefines.h>
> +
> + void testef( double *k, double *res )
> + {
> +     res = k + 1;
> + }
> + "
> >
> > sink('teste.c')
> > cat( texto_code )
> > sink()
> >
> > system("R CMD SHLIB teste.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 teste.c -o teste.o
> gcc -m64 -shared -s -static-libgcc -o teste.dll tmp.def teste.o
> -Ld:/RCompile/r-compiling/local/local320/lib/x64
> -Ld:/RCompile/r-compiling/local/local320/lib -LC:/R/bin/x64 -lR
> > dyn.load( "teste.dll" )
> > is.loaded( 'testef' )
> [1] TRUE
> >
> > k=1
> >
>
> ############################
> ##########
> #   ( .Call('testef', k=as.double(k), res=as.double(0) ) )
> #
> #  aqui o R trava e fecha !!!!!!!!!!!!!!!!!!!!!!
>
>
>
>
>
> ---
> Este email foi escaneado pelo Avast antivírus.
> https://www.avast.com/antivirus
>
> _______________________________________________
> R-br mailing list
> R-br em listas.c3sl.ufpr.br
> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e fornea cdigo
> mnimo reproduzvel.
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://listas.inf.ufpr.br/pipermail/r-br/attachments/20150921/2d1bb821/attachment.html>


Mais detalhes sobre a lista de discussão R-br