我希望能够抑制
r
中zip
命令输出的信息,但我没有找到正确的命令来实现这一点。背景是,我在函数中使用zip函数,我不想让用户看到所有文件的信息(大约5000个),因为这会使控制台混乱。到目前为止,我尝试了以下所有函数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
的输出吗?
zip
一起使用。 - David