Open DanChaltiel opened 1 year ago
Actually, if it could also access .x
or even its name, it would be tremendously useful 👍
I also think being able to access .x
would be a really helpful feature. For long running operations, it would be very useful to know which element is currently being processed. Sometimes I find that one element may take much longer than others, but it can be hard to determine which one it is (there are other ways to identify this of course, but this would be a quick and simple way)
Actually, it is already possible, but maybe purrr could have a better default, and better docs would be nice:
f <- function() {
b <- "bar"
purrr::map(
1:10,
function(x) Sys.sleep(1),
.progress = list(caller = environment(), format = "{b} {cli::pb_current}")
)
}
invisible(f())
I.e. caller
is the environment where the format string(s) are evaluated.
I think this should be reasonably straightforward to implement — in map_
, map2_
, and pmap_
, check isTRUE(.progress)
. If it is replace with the call suggested by @gaborcsardi using the .purrr_user_env
as the environment. Then just needs a test and a news bullet. (Not sure any documentation changes are needed since I think this is the behaviour that folks would expect).
Hi,
Progress bars documentation says:
However, while one would expect these expressions to evaluate in the current environment, it seems that they can only access variables declared in the global environment.
Here is a reprex. As you can see, the progress bar doesn't know about
y
(parent environment) but knows aboutx
(global environment). It doesn't know aboutz
(current environment) either, you can test it.Created on 2023-05-02 with reprex v2.0.2