[Rd] Multiple return values / bug in rpart?

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 13 14:59:16 CEST 2013


On 13/08/2013 13:54, Terry Therneau wrote:
> I don't remember what rpartpl once did myself; as you point out it is a
> routine that is no longer used and should be removed.  I've cc'd Brian
> since he maintains the rpart code.
>
> Long ago return() with multiple arguments was a legal shorthand for
> returning a list. This feature was depricated in Splus, I think even
> before R rose to prominence.  I vaguely remember a time when it's usage
> generated a warning.

Yes, usage generated a warning then an error, but not parsing.

 > foo <- function() return(a=1, b=2)
 > foo()
Error in return(a = 1, b = 2) : multi-argument returns are not permitted

> The fact that I've never noticed this unused routine is somewhat
> embarrassing.  Perhaps I need a "not documented, never called" addition
> to R CMD check to help me along.

But you cannot know 'never called'.  This is callable by 
rpart:::rpartpl() : it is also possible that functions in your namespace 
are called via eval()ing expressions at R or C level.  (There are 
examples around for which that is the only usage.)

>
> Terry Therneau
>
>> In the recommended package rpart (version 4.1-1), the file rpartpl.R
>> contains the following line:
>>
>> return(x = x[!erase], y = y[!erase])
>>
>> AFAIK, returning multiple values like this is not valid R. Is that
>> correct? I can't seem to make it work in my own code.
>>
>> It doesn't appear that rpartpl.R is used anywhere, so this may have
>> never caused an issue. But it's tripping up my R compiler.
>>
>> Thanks,
>> Justin Talbot


-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list