[Rd] Multiple return values / bug in rpart?

Duncan Murdoch murdoch.duncan at gmail.com
Tue Aug 13 17:25:13 CEST 2013


On 13-08-13 8:59 AM, Prof Brian Ripley wrote:
> 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.)

An approximation to "never called" is to run Rprof on your test code, 
and see which functions are not mentioned.  I have a package under 
construction with some students that can use this approach to identify 
which lines are never seen while profiling the test code.

Duncan Murdoch



More information about the R-devel mailing list