Hi, I have the follow function: function() { ## Init of function ... for(i in test) { ... while(j <= test2) { ... } } } The problem is that sometimes, naturally, the while is not possible to be resolved, and so the program abort. In this case I need that program return to the init of function and run again. How I can make this? Abort the while, abort the for and run the function again? Thanks Ronaldo -- Os homens ficam terrivelmente chatos quando sao bons maridos, e abominavelmente convencidos quando nao sao. -- Oscar Wilde -- |> // | \\ [***********************************] | ( ?? ?? ) [Ronaldo Reis J??nior ] |> V [UFV/DBA-Entomologia ] | / \ [36570-000 Vi??osa - MG ] |> /(.''`.)\ [Fone: 31-3899-4007 ] | /(: :' :)\ [chrysopa at insecta.ufv.br ] |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] | ( `- ) [***********************************] |>> _/ \_Powered by GNU/Debian Woody/Sarge
Is this possible: function(){ initialize <- function( ){ initialize } for(i in test){ ... if( j <= test2 ) {i <- 1; initialize()} ... } Best, Matthias> Hi, > > I have the follow function: > > function() { > > ## Init of function > ... > > for(i in test) { > ... > > while(j <= test2) { > ... > > } > } > } > > The problem is that sometimes, naturally, the while is not > possible to be > resolved, and so the program abort. > > In this case I need that program return to the init of > function and run again. > > How I can make this? Abort the while, abort the for and run > the function > again? > > Thanks > Ronaldo > -- > Os homens ficam terrivelmente chatos quando sao bons > maridos, e abominavelmente convencidos quando nao > sao. > -- Oscar Wilde > -- > |> // | \\ [***********************************] > | ( ?? ?? ) [Ronaldo Reis J??nior ] > |> V [UFV/DBA-Entomologia ] > | / \ [36570-000 Vi??osa - MG ] > |> /(.''`.)\ [Fone: 31-3899-4007 ] > | /(: :' :)\ [chrysopa at insecta.ufv.br ] > |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] > | ( `- ) [***********************************] > |>> _/ \_Powered by GNU/Debian Woody/Sarge > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html >
Em Qua 16 Nov 2005 11:30, jim holtman escreveu:> What do you mean by 'abort'? Does an 'error' occur that you want to catch? > If so, look at 'try'. Otherwise if it is testable, then just test for the > condition and restart. >Hi, this is not a real error, is a situation whitout a resolution. Is, I try to test the condition and restart, but how to restart all? Matthias suggest the use of initialize, I dont undertande how to use this. I try this: myfunction <- function(...) { ## Init of function ... for(i in test) { ... while(j <= test2) { ... test3 <- make a test if(test3 == error) { myfunction(...) } } } } This is the best way to make this? In this case I need to put all arguments initialized in function(...) on the myfunction(...) . Thanks Ronaldo -- Fa??a algo ?? prova de idiotas e algu??m far?? um idiota melhor. -- |> // | \\ [***********************************] | ( ?? ?? ) [Ronaldo Reis J??nior ] |> V [UFV/DBA-Entomologia ] | / \ [36570-000 Vi??osa - MG ] |> /(.''`.)\ [Fone: 31-3899-4007 ] | /(: :' :)\ [chrysopa at insecta.ufv.br ] |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] | ( `- ) [***********************************] |>> _/ \_Powered by GNU/Debian Woody/Sarge
Ronaldo Reis-Jr. wrote:> Hi, > > I have the follow function: > > function() { > > ## Init of function > ... > > for(i in test) { > ... > > while(j <= test2) { > ... > > } > } > } > > The problem is that sometimes, naturally, the while is not possible to be > resolved, and so the program abort. > > In this case I need that program return to the init of function and run again.Wrap the call to your function in try(), and if the result is a try-error, try it again. E.g. if your function is named f, do something like this: repeat { result <- try(f()) if (!inherits(result, "try-error")) break } Duncan Murdoch> > How I can make this? Abort the while, abort the for and run the function > again? > > Thanks > Ronaldo