2

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:

Community
  • 1
  • 1
MAB
  • 117
  • 2
  • 13

1 Answers1

3

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.

Martin Morgan
  • 45,935
  • 7
  • 84
  • 112
  • Given that the maintainer now runs his own research group, there’s unfortunately a high chance that there won’t be a quick reply (EDIT: well maybe there will, I just noticed who recently committed to it). It may be faster to fix the code (and optionally provide it to Bioconductor via a pull request). Or try another HDF5 library. There’s [h5](https://cran.r-project.org/web/packages/h5/index.html) on CRAN. No idea about its quality, but it’s actively maintained. – Konrad Rudolph Jun 30 '16 at 09:37
  • Thank you very much @Martin Morgan. You are absolutely right, which sadly means there is no quick workaround :-( I will evaluate using H5 but I don't want to have the depency on both libraries, and the code using rhdf5 is already quit big.. – MAB Jul 04 '16 at 08:51
  • I posted an item in Bioconductor's support site: https://support.bioconductor.org/p/84611/ – MAB Jul 04 '16 at 09:07
  • @MAB the maintainer updated this in the 'devel' branch version 2.17.2; unfortunately this requires [using bioc-devel](http://bioconductor.org/developers/how-to/useDevel/). – Martin Morgan Jul 04 '16 at 09:35
  • Thanks @Martin Morgan ! I will give it a try, using the devel version is not so bad for now.. – MAB Jul 05 '16 at 10:59