r-lib / callr

Call R from R
https://callr.r-lib.org/
Other
299 stars 38 forks source link

Feature request: Capture all R Console output with timestamp? #243

Open yogat3ch opened 1 year ago

yogat3ch commented 1 year ago

Original thread on {shinytest2} for context. Can there be an option to toggle timestamping of output from stderr (and also stdout) for a processx background r process via r_bg?

gaborcsardi commented 1 year ago

That is not possible for processx, but it is possible to callr. In fact, it is basically already implemented in the asciicast package, which creates a JSON file with time stamps.

yogat3ch commented 1 year ago

@schloerke It sounds like a rework of shinytest2 to use callr would be necessary, is that a substantial undertaking?

schloerke commented 1 year ago

{shinytest2} already uses {callr}, so no problem there.


I hope I'm not missing something obvious, but I don't see any usage (other than within testing code) of {callr} within {asciicast}.

I do see multiple usages of processx::poll(list(con)) inside a while loop. I believe this would block the main R session which we can't have for testing or interactive use within the terminal. For {asciicast}, you're allowed to block the main R session while the function call is performing the replay.

gaborcsardi commented 1 year ago

asciicast does not use callr, it is an alternative. It uses an embedded R in a subprocess instead of running the usual R executable from the terminal, which allows a lot more control.

So you cannot substitute callr with asciicast. But the same mechanism that is in asciicast is coming to callr soonish, and then you can have timestamps in the output.

schloerke commented 1 year ago

Sounds good. I look forward to the upcoming feature in {callr}. Thank you!

yogat3ch commented 1 year ago

Awesome, appreciative of the discussion and look forward to the forthcoming callr features!