Thanks a lot :)




________________________________
From: Liviu Andronic <landronimirc@gmail.com>

Cc: Rhelp <r-help@r-project.org>
Sent: Sat, October 30, 2010 11:31:35 AM
Subject: Re: [R] one function with 2 returnh points


> Hello everyone.
> I have written quite a big function that at the end correctly returns the 
>values
> I want. I found a rare exception that I want to cover also. The easier for me
> would be to write something like that
>
>
> function(){
>
>  if (rare exception happened)
>      return that value
>
>  # The comes the code for normal execution
>  # ...
>  # ...
>  return value # Normal values to return
>
> }
>
Are you looking for something similar?
fun <-
    function(x)
{
    if(is.character(x)){
        return(paste('Error: wrong!'))
    }
    res <- sum(1:10)
    return(res)
}

> fun('asdf')
[1] "Error: wrong!"
> fun(1:10)
[1] 55



>
>
> Would that be feasible with R or two returns statements are not accepted?
>
> Regards
> Alex
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail



      
	[[alternative HTML version deleted]]

