[Rd] return (x+1) * 1000

Dénes Tóth toth@dene@ @end|ng |rom kogentum@hu
Sat Nov 21 00:36:58 CET 2020


Yes, the behaviour of return() is absolutely consistent. I am wondering 
though how many experienced R developers would predict the correct 
return value just by looking at those code snippets.

On 11/21/20 12:33 AM, Gabriel Becker wrote:
> And the related:
> 
>     > f = function() stop(return("lol"))
> 
>     > f()
> 
>     [1] "lol"
> 
> 
> I have a feeling all of this is just return() performing correctly 
> though. If there are already R CMD CHECK checks for this kind of thing 
> (I wasnt sure but I'm hearing from others there may be/are) that may be 
> (and/or may need to be) sufficient.
> 
> ~G
> 
> On Fri, Nov 20, 2020 at 3:27 PM Dénes Tóth <toth.denes using kogentum.hu 
> <mailto:toth.denes using kogentum.hu>> wrote:
> 
>     Or even more illustratively:
> 
>     uneval_after_return <- function(x) {
>         return(x) * stop("Not evaluated")
>     }
>     uneval_after_return(1)
>     # [1] 1
> 
>     On 11/20/20 10:12 PM, Mateo Obregón wrote:
>      > Dear r-developers-
>      >
>      > After many years of using and coding in R and other languages, I
>     came across
>      > something that I think should be flagged by the parser:
>      >
>      > bug <- function (x) {
>      >       return (x + 1) * 1000
>      > }
>      >> bug(1)
>      > [1] 2
>      >
>      > The return() call is not like any other function call that
>     returns a value to
>      > the point where it was called from. I think this should
>     straightforwardly be
>      > handled in the parser by flagging it as a syntactic error.
>      >
>      > Thoughts?
>      >
>      > Mateo.
>      > --
>      > Mateo Obregón.
>      >
>      > ______________________________________________
>      > R-devel using r-project.org <mailto:R-devel using r-project.org> mailing list
>      > https://stat.ethz.ch/mailman/listinfo/r-devel
>      >
> 
>     ______________________________________________
>     R-devel using r-project.org <mailto:R-devel using r-project.org> mailing list
>     https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list