当前位置: 动力学知识库 > 问答 > 编程问答 >

r - Suppress all output from the compute.es functions

问题描述:

I'm using the compute.es package (http://cran.r-project.org/web/packages/compute.es/compute.es.pdf) to compute effect sizes. Now, when using one of the functions from this package, the result is printed even though you assign it to a vector, and I would like to surpress this.

For example,

library("compute.es")

mes(5,5,5,5,5,5,level=95,dig=2,id=NULL,data=NULL)

prints a lot of information. By using capture.output like so

library("compute.es")

capture.output(mes(5,5,5,5,5,5,level=95,dig=2,id=NULL,data=NULL))

a lot of it gets suppressed, but not all. I've had no luck with sink() (which breaks the whole function) or invisible() either.

How can I suppress all printed information from this function?

网友答案:

Version 0.2-4 of the compute.es package has a 'verbose' argument, so e.g.:

require(compute.es) # VERSION => 0.2-4

des(.3, 30, 30, verbose=FALSE)  # WILL SUPPRESS PRINTING TO CONSOLE 
网友答案:

This function is really bi-polar. Some things are printed using cat, others using message. In addition to what you've tried you can also try suppressMessages.

This worked for me.

x <- capture.output(suppressMessages(mes(5,5,5,5,5,5,level=95,dig=2,id=NULL,data=NULL)))

Alternatively, you can hack the function (use the source!) and cut out all the cat and message statements. Another way would be to add another argument to the function (like verbose) and turn on/off messages by putting them inside an if clause. E.g.

if (!is.null(data)) {
  if (verbose) {
    cat("\n")
    message("    EFFECT SIZE CALCULATION (FOR VECTOR INPUT)")
    cat("\n")
  }
...
分享给朋友:
您可能感兴趣的文章:
随机阅读: