[Rd] Request: Suggestions for "good teaching" packages, esp. with C code

Martin Becker martin.becker at mx.uni-saarland.de
Wed Feb 16 17:35:14 CET 2011


Luke,

thanks for your explanation.
I now remember that I was indeed getting an error (instead of a silent 
abort) because I did something comparable to a .Call() to "lapply" in 
section 5.11 of WRE (Writing R extensions) where expr was the body of a 
function f (literally) which contained a return()-statement. Although 
removing the return()-statement solved my problem a few years ago, I now 
know that I had better followed the next example of WRE ("lapply2") 
which is especially designed for evaluating function calls (instead of 
expressions).
So, sorry for the noise (and for blaming return()) and thanks again for 
the clarification.

Best,

   Martin

On 16.02.2011 17:11, luke-tierney at uiowa.edu wrote:
> If you evaluate return(x) in an evironment env then then that will
> execute a return from the function call associated with env or signal
> an error if there is none.  That is the way return() is intended to
> work.
>
> Best,
>
> luke
>
> On Wed, 16 Feb 2011, Duncan Murdoch wrote:
>
>> On 11-02-16 7:31 AM, Martin Becker wrote:
>>> On 15.02.2011 22:48, David Scott wrote:
>>>> On 16/02/2011 7:04 a.m., Paul Johnson wrote:
>>>>> ...
>>>>>
>>>>> 4. We don't want gratuitous use of "return" at the end of functions.
>>>>> Why do people still do that?
>>>>
>>>> Well I for one (and Jeff as well it seems) think it is good
>>>> programming practice. It makes explicit what is being returned
>>>> eliminating the possibility of mistakes and provides clarity for
>>>> anyone reading the code.
>>>>
>>>> David Scott
>>>>
>>>>
>>>
>>> AFAIR (but I am not sure, maybe some expert can comment on this), there
>>> is a difference between using return and not using return when R 
>>> code is
>>> called from C-code via eval(). If my memory is correct, a return()
>>> statement (in the R code) would abort the C function (which is 
>>> trying to
>>> evaluate the R code, e.g., the body of a function) as well, which is
>>> probably not intended. So, the use of return() in R code may be quite
>>> disadvantageous in certain situations.
>>
>> As far as I know there is no such effect.  I suspect what you saw 
>> just triggered a bug in the C code that had stayed hidden before.
>>
>> Duncan Murdoch
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>


-- 
Dr. Martin Becker
Statistics and Econometrics
Saarland University
Campus C3 1, Room 217
66123 Saarbruecken
Germany



More information about the R-devel mailing list