Skip to content
Back to formatted view

Raw Message

Message-ID: <35F51954-9AB9-44F0-81FC-E473D398377A@r-project.org>
Date: 2013-08-13T12:35:49Z
From: Simon Urbanek
Subject: Multiple return values / bug in rpart?
In-Reply-To: <CANVKczMLpt4hj=oGpxE1KVov3ftUkg2F7nJNCXr31ogby-XChA@mail.gmail.com>

On Aug 13, 2013, at 5:27 AM, Barry Rowlingson wrote:

> On Mon, Aug 12, 2013 at 6:06 PM, Justin Talbot <justintalbot at gmail.com> wrote:
>> 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.
> 
> Works for me, returning a list:
> 
>> foo
> function(x){return(x,x*2)}
>> foo(99)
> [[1]]
> [1] 99
> 
> [[2]]
> [1] 198
> 
> But hey, that might just be because I redefined 'return' earlier:
> 
>> return
> function(...){list(...)}
> 

eek.. this is bad:

> (function() { if(TRUE) return("OK"); "BAD!" })()
[1] "BAD!"

Trying to modify the behavior of return() is rather tricky since you have to return from the function that's calling you ...