Script execution is not stopping for Replicate

To help us help you, could you please prepare a minimal reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

I don't know about others, but I don't download data or run unknown code off the internet. Not saying you're malicious, it's just my general rule. Ideally, your code would look like what's in your first post, but with some creation of small objects in the beginning. For example:

# Replace this with stuff that resembles your actual data
dudelta <- runif(100)
freespace <- 1e5

f <- function(spaceleft) {
  days <- 0
  while(spaceleft > 0) {
    days <- days + 1
    spaceleft <- spaceleft - sample(dudelta, 1, replace=TRUE)
  }
  days
}

daysleft <- replicate(5, f(freespace))

Every problem I've had with while loops came from bad assumptions on my part. In your case, dudelta might not have the kind of values you think it does.

1 Like