[R] Why 'return' is needed in R?

Peng Yu pengyu.ut at gmail.com
Tue Oct 27 15:12:56 CET 2009


It seems that 'return' is not necessary when returning a value. If
this is the case, I don't understand why 'return' is a keyword in R.
Is there a case in which I have to use 'return'?

> f<-function(x) {
+   x
+ }
> g<-function(x) {
+   return(x)
+ }
> print(f(2))
[1] 2
> print(g(2))
[1] 2
>




More information about the R-help mailing list