reprex 忽略 system() 的输出

reprex ignores output of system()

考虑以下跨平台测试:

> system('echo hello')
hello

如果在 RStudio 中我复制字符串 system('echo hello') 和 运行 reprex::reprex() 输出未被捕获:

有什么方法可以捕获输出吗?我在 macOS 上。

也许设置 std_out_err = TRUE 就可以了。来自函数文档:

std_out_err Logical. Whether to append a section for output sent to stdout and stderr by the reprex rendering process. This can be necessary to reveal output if the reprex spawns child processes or system() calls. Note this cannot be properly interleaved with output from the main R process, nor is there any guarantee that the lines from standard output and standard error are in correct chronological order. See callr::r() for more. Read more about opt().

system("echo hello")
x <- 1
x
#> [1] 1

标准输出和标准错误

hello

reprex package (v0.3.0)

于 2019-06-24 创建