Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.A41.4.33.0109140921570.130734-100000@homer03.u.washington.edu>
Date: 2001-09-14T16:27:39Z
From: Thomas Lumley
Subject: "return" function
In-Reply-To: <D8FC432ED011D511B1D9001083FD45E70F35F7@norcom2.norcom.net>

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 at 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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._