【问题标题】:R - capture output from system() to a txt file.R - 将 system() 的输出捕获到 txt 文件。
【发布时间】:2019-04-19 03:26:34
【问题描述】:

我想从 R 控制台捕获所有输出。我尝试使用库“TeachingDemos”的 sink() 函数和 txtStart()。但是,它们都不能捕获 system() 命令的输出。

例如 如果我运行以下代码:

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()

我可以在 R 控制台中看到消息“hello world”。但是,我无法将其写入 log.txt。有没有办法解决这个问题?

谢谢

【问题讨论】:

  • system(..., intern=TRUE) (?system)

标签: r logging sink


【解决方案1】:
system("Rscript test1.R", intern = TRUE)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 2020-01-07
    • 2021-12-23
    相关资源
    最近更新 更多