[Bioc-devel] programming note: return() is a function call

Rainer Johannes Johannes.Rainer at eurac.edu
Mon Nov 14 14:39:40 CET 2016


Fixed in ensembldb

thanks Martin!


> On 14 Nov 2016, at 11:37, Martin Morgan <Martin.Morgan at RoswellPark.org> wrote:
> 
> An interested R-help thread (starting at https://stat.ethz.ch/pipermail/r-help/2016-November/443123.html) points out that return() is treated as a function by the R parser. This has some surprising consequences when it is used without parentheses, for instance
> 
> f0 = function(i)
>    return (i + 1) * 2
> 
> f1 = function() {
>    if (TRUE)
>        return
>    1
>    2
> }
> 
> > f0(10)
> [1] 11
> > f1()
> [1] 2
> 
> Suspicious code in the Bioconductor archive includes
> 
> ./AnnotationHubData/R/updateResources.R : 67           return ## recipe will download
> ./AnnotationHubServer/R/downloadAndUpdate.R : 351               return ## recipe will do necessary downloading
> ./ChAMP/R/champ.reffree.R : 38           return
> ./CompGO/R/fullPipeline.R : 138                   return
> ./DiffBind/R/DBA.R : 1287         return
> ./DiffBind/R/helper.R : 372         return
> ./ensembldb/inst/shinyHappyPeople/server.R : 115               return
> ./ensembldb/inst/shinyHappyPeople/server.R : 126               return
> ./ensembldb/inst/shinyHappyPeople/server.R : 137               return
> ./immunoClust/R/meta.plot.R : 129       return
> ./immunoClust/R/meta.plot.R : 187       return
> 
> A funny false positive is along the lines of
> 
>    if (test) {
>        stop("test failed")
>        return
>    }
> 
> where of course the (incorrect) return() is never reached.
> 
> Martin
> 
> 
> This email message may contain legally privileged and/or...{{dropped:2}}
> 
> _______________________________________________
> Bioc-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel



More information about the Bioc-devel mailing list