processx
processx copied to clipboard
Put background job output on the RStudio job pane
poc on Unix:
unlink("/tmp/fifo")
system("mkfifo /tmp/fifo")
script <- quote({
conn <- processx::conn_create_file("/tmp/fifo")
repeat {
out <- processx::conn_read_chars(conn)
if (nchar(out) == 0) break
cat(out)
}
})
cat(deparse(script), file = "/tmp/script.R", sep = "\n")
id <- rstudioapi::jobRunScript("/tmp/script.R")
id
pp <- processx::process$new(
"bash",
c("-c", "for i in `seq 1 100`; do sleep 1; echo $i; done"),
stdout = "/tmp/fifo"
)
# Now you can even do these and more
pp$suspend()
pp$resume()
# rstudioapi::launcherControlJob(id, "kill")
rstudioapi::jobRemove(id)
API can be stdout = "|rstudio" or we can even have a new function that does this, and inherit from process and add methods to manage the rstudio job. But then it will no work for the other subclasses, like r_process.