r-lib / progress

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

Can we have an "appendLF" option in the message() method? #106

Closed zhuxr11 closed 4 years ago

zhuxr11 commented 4 years ago

Sometimes I use the progress bar to check the progress of a whole pipeline. For some specific steps in the pipeline, I'd like to use message() to monitor what specific folder the pipeline is processing, but with current message() method I will get one row of message for each of the folder name printed out, flushing my console with all these folder names printed out (e.g. when there are hunders of folders processed). Since the built-in message function have an option "appendLF" which can overwrite previous message with "\r", I'm wondering if you can put this argument as an option in the message() method? Many thanks.

gaborcsardi commented 4 years ago

I am not sure what you mean. What progress currently does in message() is:

  1. delete the progress bar
  2. print out the message
  3. print out a newline
  4. write back the progress bar

If we don't print out a newline, then the progress bar will immediately overwrite the message.

zhuxr11 commented 4 years ago

Hi, thanks for your prompt reply. What I desired is something like this:

For example, in the 3rd step of a 10-step pipeline, I am processing files in 10 folders, I'd like to print message like this:

Processing folder 1: using some command like message("folder 1\r", appendLF = FALSE)

folder 1 [==>-------] 30%

Processing folder 2: using some command like message("folder 2\r", appendLF = FALSE)

folder 2 [==>-------] 30%

Processing folder 3:

folder 3 [==>-------] 30%

After all the 10 folders processed, it becomes the following: message gets erased because I used "\r" with appendLF = FALSE

[===>------] 40%

Currently, with the pb$message() method, I am getting:

folder 1 folder 2 folder 3 folder 4 folder 5 folder 6 [==>-------] 30%

And finally:

folder 1 folder 2 folder 3 folder 4 folder 5 folder 6 folder 7 folder 8 folder 9 folder 10 [===>------] 40%

Imagine if I have e.g. 200 folders to process instead of 10 listed here, they will take over my whole screen and flush any information printed before that.

I think a work-round can be updating the folder name in format as a custom token and update them with pb$tick(0, token = list(...)). But I think having erasable messages above the progress bar is also desirable.

Not sure whether this makes sense or not.

zhuxr11 commented 4 years ago

So I see, this is currently not quite feasible, since the progress bar needs to rewind to the start of the PREVIOUS line to erase the printed message. It is quite hard. I am thinking of using the folder name as a token and update it with pb$tick(0) then.

gaborcsardi commented 4 years ago

It is quite hard.

It is not hard. Just not supported at all in RGui, R.app, RStudio, etc. It is only supported in proper terminals.