Explicitly calling return in a function or not

A while back I got rebuked by Simon Urbanek from the R core team (I believe) for recommending a user to explicitly calling return at the end of a function (his comment was deleted though):

foo = function() {
  return(value)
}

instead he recommended:

foo = function() {
  value
}

Probably in a situation like this it is required:

foo = function() {
 if(a) {
   return(a)
 } else {
   return(b)
 }
}

His comment shed some light on why not calling return unless strictly needed is a good thing, but this was deleted.

My question is: Why is not calling return faster or better, and thus preferable?

9 Answers
9

Leave a Comment