I want to capture all output from R console. I tried to use sink() function and txtStart() of library 'TeachingDemos'. However, none of them can capture the output from system() command.
For example If I run the below codes:
zz <- file("log.txt")
sink(zz)
sink(zz, type = "message")
print('first layer message!!!!')
system("Rscript test1.R") #test1.R is a R script that print 'hello world'
sink(type = "message")
sink()
I can see the message 'hello world' in the R console. However, I cannot write it into log.txt. Is there any way to solve this?
Thanks