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.
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).
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%)
# 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
?
- Stack Overflow How can you always suppress messages in R? The most common place I've seen messages used in R is in the starting of a package. Suppressing one function's worth of messages is easily accomplished with suppressMessages as discussed here: Disable Messages Upon Loading Package in R.
To unzip the files in R, use the unzip () method. The unzip () method unpacks all the files and distributes them inside the current working directory. It will unpack the sources.zip file. If you want to see the contents inside the zip file, use the unzip () function and pass the second argument as a list.
Figure 1 shows the messages that we receive when starting the dplyr package in RStudio. If we want to disable such messages, we can use the suppressPackageStartupMessages function as shown below:
By using invisible () function we can suppress the output. Example: R program to create a vector, list, and dataframe and suppress the output For both the examples, no output will be generated, since the entire aim of this article is to suppress output. How to suppress the vertical gridlines using ggplot2 in R?
The answer will depend on the system that the code is used on. On my Windows system, I can use
zip("zip.zip", "hw.txt", flags="-q")
and it suppresses messages, but it depends on what your system uses to handle zip files. Since the message is coming from the zip program, you must signal it not to output messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With