From tplate at blackmesacapital.com  Fri Jun 18 17:47:23 2004
From: tplate at blackmesacapital.com (Tony Plate)
Date: Fri Jun 18 17:47:35 2004
Subject: [Rd] .C() vs .Call() (was Re: R-devel and not R-help (was 'using "=
 matrix (...)" in .C calls')
In-Reply-To: <16594.42254.680716.993405@gargle.gargle.HOWL>
References: <OFA53FF1DF.EBC14134-ON85256EB6.0052F4B7-85256EB6.00569613@EU.novartis.net>
	<6.1.0.6.2.20040617103352.0cf67ec0@mailhost.blackmesacapital.com>
	<x2n032w2lq.fsf@biostat.ku.dk>
	<16594.42254.680716.993405@gargle.gargle.HOWL>
Message-ID: <6.1.0.6.2.20040618092430.0cfd0bc0@mailhost.blackmesacapital.com>

At Friday 02:17 AM 6/18/2004, Martin Maechler wrote:

>[snip]  Even though we (R core) would like to promote the use
>of .Call() as much as possible, for most R users, [snip]

Why does "R core" wish to promote the use of .Call() over .C()?

I see two advantages for .C():

(1) The interface is very straightforward and I don't need to go to the 
trouble of using R macros and extractor functions in my C or C++ code in 
order to get at the data -- the data is just passed in C vectors of 
standard types, and I can return data the same way.  This means my C code 
is simpler and consequently (on average) more maintainable and less prone 
to bugs.  For example, consider the C functions 'convolve' (to be called by 
.C()) and 'convolve2' (to be called by .Call()) that are in "Writing R 
Extensions".  I am more confident that I can write correctly the R code for 
type checking and coercion needed for the .C() call than I can write 
correctly the corresponding C code (for example, because then I need to 
think about things like stack imbalances in my calls to PROTECT/UNPROTECT).

(2) .C() functions are easier to port between different implementations of 
the S language.

Am I missing advantages to using .Call() when .C() would suffice?  (i.e., 
when the data that must be passed back and forth can be easily packed into 
vectors.)

-- Tony Plate


[Rd] .C() vs .Call() (was Re: R-devel and not R-help (was 'using "= matrix (...)" in .C calls')
Tony Plate