Skip to content

Is it possible to support local(..., envir = environment())? #195

Description

@HenrikBengtsson
library(progressr)
handlers(global = TRUE)

xs <- 1:5
local(envir = environment(), {
  p <- progressor(along = xs)
  y <- lapply(xs, slow_sum)
})

gives

Error in progressor(along = xs) : 
  A progressor must not be created in the global environment unless wrapped in a with_progress()
  or without_progress() call. Alternatively, create it inside a function or in a local() environment to 
  make sure there is a finite life span of the progressor

but it should be possible to support that, because:

> local(envir = environment(), { on.exit(message("done")) })
done

BTW, we could even target:

> local(envir = NULL, { x <- 42; on.exit(message("done")) })
done
> x
[1] 42

which is a tad easier to type;

local(envir = NULL, {
  p <- progressor(along = xs)
  y <- lapply(xs, slow_sum)
})

or even

local({
  p <- progressor(along = xs)
  y <- lapply(xs, slow_sum)
}, NULL)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions