Re: [Rd] Multiple return values / bug in rpart?

2013-08-13 Thread Simon Urbanek

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

 On Mon, Aug 12, 2013 at 6:06 PM, Justin Talbot justintal...@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 ...

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Multiple return values / bug in rpart?

2013-08-13 Thread Terry Therneau
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.


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.


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


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Multiple return values / bug in rpart?

2013-08-13 Thread Prof Brian Ripley

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,  rip...@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, UKFax:  +44 1865 272595

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Multiple return values / bug in rpart?

2013-08-13 Thread Duncan Murdoch

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

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Multiple return values / bug in rpart?

2013-08-13 Thread luke-tierney

Both codetools and the compiler should be checking for use of multiple
args in return -- I'll look into adding that.

Best,

luke

On Tue, 13 Aug 2013, Duncan Murdoch wrote:


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

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Multiple return values / bug in rpart?

2013-08-13 Thread John Chambers
And just in case anyone is curious about the history, return() with 
multiple arguments was legal in S2 but the syntax in the blue book had 
only return(expr), whether enforced or not in the code.


  John


On 8/13/13 11:42 AM, luke-tier...@uiowa.edu wrote:

Both codetools and the compiler should be checking for use of multiple
args in return -- I'll look into adding that.

Best,

luke

On Tue, 13 Aug 2013, Duncan Murdoch wrote:


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

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel





__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Multiple return values / bug in rpart?

2013-08-12 Thread Justin Talbot
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

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel