Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The case for a quickly() adverb function #1072

Closed
jl5000 opened this issue Apr 13, 2023 · 1 comment
Closed

The case for a quickly() adverb function #1072

jl5000 opened this issue Apr 13, 2023 · 1 comment

Comments

@jl5000
Copy link

jl5000 commented Apr 13, 2023

I think it would be useful to have an adverb function quickly() which will limit the amount of time spent trying to execute a function. If a given time is exceeded, it can either throw an error, warning, or move on silently.

I am currently using something like this when calling a function for its side effects but am dealing with slow/unreliable network connections. Perhaps for functions that return values, a default value could be defined.

I'm currently doing something like this:

do_it_fast <- function(){
  success <- FALSE
  tryCatch({
    
    time_limit <- 2
    
    setTimeLimit(cpu = time_limit, elapsed = time_limit, transient = TRUE)
    
    # Do stuff
    success <- TRUE
    
  }, error = function(e) {
  }, warning = function(w) {
  }, finally = {
    setTimeLimit(cpu = Inf, elapsed = Inf, transient = FALSE)
  })
  success
}
@hadley hadley closed this as completed Jul 26, 2023
@hadley
Copy link
Member

hadley commented Jul 26, 2023

setTimeLimit() only applies to top-level computations, so I don't think it's possible to implement the function that you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants