rrstudiosuppress-warningsbioconductorrhdf5

How to avoid printing / showing messages


this question has been asked before but non of the answers is working for me.

I am using the library rhdf5 from bioconductor.org to read HDF5 files: source("http://bioconductor.org/biocLite.R"); biocLite("rhdf5"); library(rhdf5);

When I use the h5read function to read particular variables that contain references the following warning message is printed:

"Warning: h5read for type 'REFERENCE' not yet implemented. Values replaced by NA's"

(It is not shown in red like errors and warnings in RStudio. Just in black)

The warning is OK for me as I don't need those references. But I use this function to read hundreds of variables, so my screen gets polluted with these messages. For example:

a <-h5read(f, "/#Link2#")
Warning: h5read for type 'REFERENCE' not yet implemented. Values replaced by NA's
Warning: h5read for type 'REFERENCE' not yet implemented. Values replaced by NA's

I have tried all suggestions I found (capture.output, suppressMessage/Warning, sink, options(warn, max.print, show.error.messages):

  1. capture.output(a <- h5read(f, "/#Link2#"), file='/dev/null')
  2. I also tried invisible just in case: invisible(capture.output(a <- h5read(f, "/#Link2#"), file='/dev/null'))
  3. suppressWarnings(suppressMessages(a <- h5read(f, "/#Link2#")))
  4. I also tried suppressForeignCheck and suppressPackageStartupMessages just in case
  5. {sink("/dev/null"); a <-h5read(f, "/#Link2#"); sink()}
  6. {options(warn=-1, max.print=1,show.error.messages=FALSE); a <-h5read(f, "/#Link2#") }

They all keep producing the same warning messages.

Does anyone knows any other thing I might try, or why are these things not working?

How does the library manages to print the messages skipping all these? Sounds that I might be doing something wrong...

Any help is appreciated.

Just as reference these are the other posts I used:


Solution

  • You should ask maintainer("rhdf5") to provide a solution -- print message less frequently, and use standard R warnings -- the message is from C code and uses printf() rather than Rf_warning() or Rf_ShowMessage() or Rprintf() / REprintf().

    Here's an illustration of the problem

    > library(inline)
    > fun = cfunction(character(), 'printf("hello world\\n"); return R_NilValue;')
    > fun()
    hello world
    NULL
    > sink("/dev/null"); fun(); sink()
    hello world
    > 
    

    and a solution -- use Rf_warning() to generate R warnings. The example also illustrates how writing to R's output stream via Rprintf() would then allow the output to be captured with sink.

    > fun = cfunction(character(), 'Rf_warning("hello world"); return R_NilValue;')
    > x = fun()
    Warning message:
    In fun() : hello world
    > x = suppressWarnings(fun())
    > fun = cfunction(character(), 'Rprintf("hello world\\n"); return R_NilValue;')
    > sink("/dev/null"); fun(); sink()
    >
    

    None of this helps you directly, though!

    UPDATE the maintainer updated the code in the 'devel' branch of the package, version 2.17.2.