0

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

Robin1988
  • 1,504
  • 4
  • 20
  • 25
  • `system(..., intern=TRUE)` ([`?system`](https://www.rdocumentation.org/packages/base/versions/3.5.1/topics/system)) – r2evans Nov 15 '18 at 23:44

1 Answers1

3
system("Rscript test1.R", intern = TRUE)
Rohit Das
  • 1,962
  • 3
  • 14
  • 23