From antonio.fabio at gmail.com  Thu Jan 22 17:31:22 2009
From: antonio.fabio at gmail.com (Antonio, Fabio Di Narzo)
Date: Thu, 22 Jan 2009 11:31:22 -0500
Subject: [Rd] Accessing a c-level complicated structure from R
In-Reply-To: <e9ee1f0a0901220730k7013c02sbac7cba06ce459c8@mail.gmail.com>
References: <e9ee1f0a0901220730k7013c02sbac7cba06ce459c8@mail.gmail.com>
Message-ID: <b0808fdc0901220831j32484413v79c8575b6d9d91d@mail.gmail.com>

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



[Rd] Accessing a c-level complicated structure from R
Antonio, Fabio Di Narzo