Re: [R] "return" function

About this list Date view Thread view Subject view Author view Attachment view

From: Thomas Lumley (tlumley@u.washington.edu)
Date: Sat 15 Sep 2001 - 02:27:39 EST


Message-id: <Pine.A41.4.33.0109140921570.130734-100000@homer03.u.washington.edu>

On Fri, 14 Sep 2001, Chris Marshall wrote:

> I tried to write a function like this
>
> f1 <- function(){
> if (condition 1) return
> if (condition 2) return
> ...
> if (condition 3) return
>
> do more work
> }
>
> Where I am using return to exit the function prematurely when I detect
> conditions that warrant it. Return doesn't seem to work this way.
>
> How should I do this?

You need to evaluate the function

 if (condition1) return()
 if (condition2) return()
etc

It's the same for all functions -- at the command line, for example, if
you type the name of a function without parentheses you just get the
source code for the function listed.

        -thomas

Thomas Lumley Asst. Professor, Biostatistics
tlumley@u.washington.edu University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Thu 17 Jan 2002 - 11:10:06 EST