sink function with future.callr

46 views Asked by At

I have this R script:

test.R

library(future.callr)   
plan(callr)

executeInternalActivity<-function(){

 sink(file = "output.txt",append = TRUE)    
 print(Sys.time())
 Sys.sleep(3)
 print(Sys.time())    
 sink()

}

executeInternalActivity()    
#future({executeInternalActivity()})

When test.R is executed: source("test.R") (Note the calling to executeInternalActivity), the output.txt is created properly

[root@db1 Rscripts]# cat output.txt
[1] "2023-08-27 15:51:25 GMT"
[1] "2023-08-27 15:51:28 GMT"

However, if we change the calling to executeInternalActivity to do it with future:

#executeInternalActivity()
future({executeInternalActivity()})

... and then execute it:

source("test.R")

Only the first print appears in the output.txt file:

[root@db1 Rscripts]# cat output.txt
[1] "2023-08-27 16:10:55 GMT"

I would like all prints to appear in the output.txt file. How can I fix it?

0

There are 0 answers