r-lib / progress

Progress bar in your R terminal
http://r-lib.github.io/progress/
Other
468 stars 39 forks source link

progress bar does not show up when sourcing script as local job in RStudio #104

Closed mattwarkentin closed 4 years ago

mattwarkentin commented 4 years ago

Hi @gaborcsardi,

I have noticed that the progress bar does not show up when sourcing the script as a local job in RStudio. For example, if I source the below script in the main R session, the progress bar works fine. It also works when running via Rscript ... at the command line/terminal. However, when sourcing the job in a background R session as is done with Source > Source as Local Job... the progress does not appear.

library(progress)
pb <- progress_bar$new(clear = FALSE)
purrr::walk(1:100, ~{pb$tick(); Sys.sleep(0.1)})

Any idea why this does not work? I presume it has something to do with not being considered valid R output. But not sure if there is a workaround.

mattwarkentin commented 4 years ago

After some digging I see that using the force = TRUE argument will force the progress bar to be shown even if the local job console does not support streaming messages.

I do see that package startup messages are printed in the local job console. Are "plain" messages difference than startup messages?

mattwarkentin commented 4 years ago

While I'm here, is there any way to use crayon to change the colours of the progress bar? I see the progress bar you have in pak and would love to be able to further customize these progress bars similarly.