Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress Messages from zip in R

Tags:

output

r

zip

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?

like image 908
David Avatar asked Aug 20 '17 10:08

David


People also ask

How can you suppress messages in R?

- 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.

How to unzip the files 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.

How do I disable dplyr Startup messages in RStudio?

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:

How to suppress the output of a vector in R?

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?


1 Answers

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.

like image 151
G5W Avatar answered Sep 20 '22 11:09

G5W