[R] Re: your mail
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Thu May 27 22:12:36 CEST 1999
On Thu, 27 May 1999, Jonathan Myles wrote:
> I am currently preparing an R library to estimate
> approximate posterior distributions for parameters in
> Generalised Linear Mixed Models by Gibbs Sampling
> which includes a lot of dynamically loaded C code.
If this is a version of your S glmm codes, we very much look forward to it.
> I'm pleased with the way in which it is working and am
> now hammering out some documentation, but closer consideration
> of some R documentation has led me to worry that my code
> a) may not achieve certain standards of R and C programming
> and b) may not work on all systems. (I'm using 0.64.1
> on a UNIX system)
>
> My worries are
>
> a) That I've used calloc rather than S_alloc throughout.
Just use Calloc and Free: these are defined in S.h and (a) let R do the
error-checking and (b) on Windows ensures you get a malloc that can
actually free space.
> b) That I've used the following technique: I've
> calls to different C programs held together in a single
> file which looks like:
>
> GLM g; /* information about the model */
> OUTPUT o; /* information about the output *
>
> f1(g){ ....... }
> f2(g,o) { ......}
>
>
>
> (GLM and OUTPUT are
> typedefs defined in a .h file)
>
>
> with an R function that looks like :
> {
> <R statements>
>
> .C("f1",.....)
>
> <R statements>
>
> .C("f2",.....)
>
> <R statements>
>
> ...
>
> }
>
> and I rely on the fact that "g" and "o" remain the same between the successive
> calls (there's a C call at the end to free up all the memory). is this:
>
> 1) bad,
> 2) so bad (-;) that the R archive wouldn't really be interested in code
> that worked in this way?
I am not clear about this. Do you rely on g and o remaining the same
or their addresses remaining the same? And if the latter, you don't need
to pass g in again. Garbage collection will move objects, but nothing
in R will alter them. So on my second reading of this, there is no
problem. You might want to try us on a more specific example.
> I *think* I can do it without using this technique, but it will need a lot
> of re-programming. One way round it in S v5 uses the new .Call()
> function---is anything similar on the agenda for future versions of R?
(It is S-PLUS 5.x or Sv4, I think.)
There is already a .External call for a very similar purpose. I find
programming R internals a little easier than .Call().
> On another note, where in the library structure would be a good
> place to put a LaTeX document describing the function and showing
> some examples?
Anything you put in inst gets installed, so I would suggest in inst/doc.
By no means all R users have LaTeX, so give a .ps or a .pdf version too,
please.
Brian Ripley
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list