【发布时间】:2018-01-28 14:19:10
【问题描述】:
我想在r 中抑制zip 命令输出的消息,但我找不到执行此操作的正确命令。
背景,当我在函数中使用 zip 函数时,我不希望用户看到所有文件的所有信息(大约 5.000,这会使控制台混乱)。
这是我迄今为止尝试过的,但所有函数 foo 都显示 adding: hw.txt (stored 0%) 或 updating: hw.txt (stored 0%)
# create a small file
writeLines("hello world", "hw.txt")
# use the original command
zip("zip.zip", "hw.txt")
# try different options of capturing/suppressing output!
# assignment
foo1 <- function() a <- zip("zip.zip", "hw.txt")
foo1()
# capture.output
foo2 <- function() a <- capture.output(zip("zip.zip", "hw.txt"))
foo2()
# suppressMessages
foo3 <- function() suppressMessages(zip("zip.zip", "hw.txt"))
foo3()
# invisible
foo4 <- function() invisible(zip("zip.zip", "hw.txt"))
foo4()
# sink
foo5 <- function() {
sink(tempfile())
zip("zip.zip", "hw.txt")
sink()
}
foo5()
还有其他选项可以抑制zip 的输出吗?
【问题讨论】:
-
使用的语言是什么?
-
我使用 R(我更新了问题以使其更明显)
-
确实有,这就是我找到上面展示的 5 种方法的地方。但它们似乎不适用于
zip。