[Rd] Accessing a c-level complicated structure from R
Antonio, Fabio Di Narzo
antonio.fabio at gmail.com
Thu Jan 22 17:31:22 CET 2009
Hi.
2009/1/22 Scionforbai <scionforbai at gmail.com>:
> Hello,
> R-devel seems to be the appropriated list for what I'm to ask: soory
> if I'm wrong. I am a c newbie but nevertheless I am trying to 'couple'
> an extern c software with R. The compiled library is actually a
> stand-alone c program, which uses text file for input and output. It
> uses *lots* of differents and (to me) rather complicated and nested
> "struct"s to represent data for intern calculation. I want to make
> this program a -shared lib to use with R.
> I have (among many others) the following question: can I access from R
> a c-level defined struct, as input/output of my .C called function? If
> yes... how?
>
If you have to pass these data structures up to R you have to use the
.Call interface and wrap your C objects in an extern ptr R obj. That's
described in "Writing R extensions".
Let me note you're undertaking a major work. If the software isn't
conceived as being used as a shared library, it can be much work to
translate it that way.
You can consider to use the external program as is, i.e. a stand-alone
program, and use temp text files for input-output. You can wrap it in
convenient R functions, and keep all that invisible to the end user.
This would require much less work... That's for instance how RTisean
and some BUGS related CRAN packages works, and I'm sure there are
others there.
> Any clue, manual, tutorial on c programming with R (other than R-exts
> and R-ints), and hint is greatly appreciated...
Actually, R-exts has the info you need. Look at it more carefully. You
don't even need R-ints.
HTH,
a.f.
> Thanks,
> Scion
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Antonio, Fabio Di Narzo
Ph.D. student at
Department of Statistical Sciences
University of Bologna, Italy
More information about the R-devel
mailing list