Hi everybody.

Consider the following exampling code: 

x=numeric()
  for(i in 1:10){
    u=runif(1,-1,2)
    x[i]=log(u)
  }
This code, in each interation, generates a random value in the (-1,2) interval and then calculates the log of the value. 
When the generated value is less than 0 the log produces a NaN, which gives a warning.

What I want is to make it start over when a warning is produced, in order to repeat it until a positive value is generated and therefore the log is calculated. Logically, would be like: "if there's a warning here, go back at the beginning and start over", without changing the iteration.

Could someone help me with some directions?

Thanks a lot,

Ricardo 		 	   		  
	[[alternative HTML version deleted]]

