1

I want to print debug info in an R future call to display information about how long some process (e.g. copying a file) takes.

future::plan(future::multisession)

copyInBackground <- function(from, to, overwrite = FALSE) {
  future::future( {
    jamba::printDebug("Starting ...")
    fs::file_copy(path = path.expand(from),
                  new_path = path.expand(to),
                  overwrite = overwrite)
    jamba::printDebug("Done.") 
      }
    )
}

copyInBackground(from = "~/test.png", to = "H:/test/", overwrite = TRUE)

test <- copyInBackground(from = "~/test.png", to = "H:/test/", overwrite = TRUE)
future::value(test)

My expectation: The file is copied, and console output with timestamps from jamba::printDebug.

I get some info on the MultisessionFuture if I call the function directly; and I get the timestamps only if I retrieve the value of the test object.

Is there a way for the function to print output to the console immediately, or at least automatically once the job is finished?

mzuba
  • 1,226
  • 1
  • 16
  • 33
  • Explanation for why it doesn't work: Hi, don't know what the **jamba** package, but if it's outputting to the standard output, via the `message()` function, then such output is only relayed when the future completes and its value is retrieved by the main R session, i.e. in your example when you call `future::value(test)`. – HenrikB Feb 03 '22 at 03:46
  • Alternative solution: Since you indicate you're interested in following the progress while the future is still active, then I suggest that you look at the **[progressr](https://progressr.futureverse.org/)** package. It is designed so that it can signal progress in a near-live fashion when parallelizing using the **future** framework. – HenrikB Feb 03 '22 at 03:49

0 Answers0