简体   繁体   English

禁止R中的zip邮件

[英]Suppress Messages from zip in R

I want to suppress the messages as outputted by the zip command in r but I fail to find the right command to do so. 我想抑制r zip命令输出的消息,但是找不到正确的命令来执行此操作。

Background, as I use the zip-function within a function, I don't want the user to see all information about all the files (roughly 5.000, which clutters the console). 背景,当我在函数中使用zip函数时,我不希望用户看到有关所有文件的所有信息(大约5.000,这会使控制台混乱)。

Here is what I have tried so far, but all functions foo show either adding: hw.txt (stored 0%) or updating: hw.txt (stored 0%) 这是到目前为止我尝试过的方法,但是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()

Are there any other options to suppress the output of zip ? 还有其他抑制zip输出的选项吗?

The answer will depend on the system that the code is used on. 答案将取决于使用该代码的系统。 On my Windows system, I can use 在Windows系统上,我可以使用

zip("zip.zip", "hw.txt", flags="-q")

and it suppresses messages, but it depends on what your system uses to handle zip files. 并禁止显示消息,但这取决于您的系统用于处理zip文件的方式。 Since the message is coming from the zip program, you must signal it not to output messages. 由于该消息来自zip程序,因此您必须发出信号以使其不输出消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM