Open vjcitn opened 8 months ago
This isn't a problem in and of itself, rhdf5 is just producing unnecessary messages here.
The cause is our decision to store NA_integer_
(usually from the colData
) as -2^31 within the HDF5 file. rhdf5 complains because it thinks that we actually wanted to store an integer -2^31, and that is impossible to represent within an integer vector when reading the file back into R.
The solution is just to silence rhdf5, possibly by providing an option to not emit these messages if the caller knows what they're doing with respect to these integer NAs. @grimbough?
I think that the message can be silenced by setting the rhdf5-NA.OK
on the dataset. This is something that high-level function rhdf5::h5write()
does automatically for you:
library(rhdf5)
m <- matrix(c(1:11,NA), ncol=3)
h5write(m, "test.h5", "m")
h5readAttributes("test.h5", "m")
# $`rhdf5-NA.OK`
# [1] 1
h5read("test.h5", "m")
# [,1] [,2] [,3]
# [1,] 1 5 9
# [2,] 2 6 10
# [3,] 3 7 11
# [4,] 4 8 NA
However, lower-level function rhdf5::H5Dwrite()
does not set this attribute:
h5createDataset("test.h5", "m2", dim(m), storage.mode="integer")
fid <- H5Fopen("test.h5")
did <- H5Dopen(fid, name="m2")
H5Dwrite(did, m)
H5Dclose(did)
H5Fclose(fid)
h5readAttributes("test.h5", "m2")
# list()
h5read("test.h5", "m2")
# The value -2^31 was detected in the dataset.
# This has been converted to NA within R.
# [,1] [,2] [,3]
# [1,] 1 5 9
# [2,] 2 6 10
# [3,] 3 7 11
# [4,] 4 8 NA
So it looks like the fix is to simply add the rhdf5-NA.OK
attribute to these datasets.
Yes, if the dataset was both generated and read by rhdf5 only. However, there are clients in other frameworks (e.g., Python, Javascript) that are writing these files, and it is a bit odd to ask them to insert an rhdf5-NA.ok
attribute just to silence rhdf5.
Using -2^31 to represent a missing value must be conveyed one way or another, and that "special meaning" should be part of the data itself. Otherwise how are your Python or Java clients going to know about the real meaning of -2^31 here?
You could argue that the name of the attrribute (rhdf5-NA.OK
) is a little bit unfortunate though, as it suggests that this is an rhdf5 thing. But it's not. This is essential language-agnostic metadata.
We have a separate placeholder attribute that provides more flexibility for encoding missingness, see here. I don't expect rhdf5 to respect this, I just want it to be quiet while I handle things in alabaster.base.
How about using suppressMessages(h5read(...))
or suppressMessages(H5Dread(...))
in alabaster.base then? Since ArtifactDB datasets follow a strict policy, the risk of hiding other critical messages from the end user seems very very low.
Yeah, I guess. Absent any other solution, suppressMessages
would be the way. I don't like wholesale suppression but currently there isn't another solution.
... which is a shame. If H5Dread
is intended to be a low-level function, it should just shut up and give me the data without complaints. For example, H5Dwrite
doesn't try to do anything extra with NAs; for symmetry purposes if nothing else, H5Dread
should just be similarly NA-unaware.
NA checks should be shifted to a higher level function - h5read
, perhaps, given that h5write
is also responsible for adding the rhdf5-NA.OK
attribute.
Agreed. Symmetry is important.
I don't think I have much more to add to the context here. @hpages summarise the intent behind that message well; it's to inform someone reading non-R generated data that INT_MIN
will be represented as NA
in R. It's just a message, not even a warning, and suppresMessages()
would be my immediate suggestion.
You could argue that the name of the attrribute (rhdf5-NA.OK) is a little bit unfortunate though, as it suggests that this is an rhdf5 thing. But it's not. This is essential language-agnostic metadata.
I think I choose the name to indicate the specific software that added the attribute, in the case that someone recieved data written with rhdf5 and wanted to know what the attriubte meant. Hopefully a google would find something relevant. Perhaps it could have been R-NA.OK
or similar, but given tools like hdf5r
don't do this I wanted to make the source somewhat explicit. I had the vision that the may be additional metadata added over time and the could all be stored with the rhdf5-
naming convention, but that hasn't come to pass.
NA checks should be shifted to a higher level function - h5read, perhaps, given that h5write is also responsible for adding the rhdf5-NA.OK attribute.
This I can get behind. I agree that the symmetry between the various h5
functions and (likewise H5<Xfoo>
) is desireable. I'm pretty sure the check for printing that message is already in a seperate function, so I can probably just move where it is called.
The printing of these messages has now been moved h5read
as of rhdf5 2.47.6.
Thanks @grimbough
Also no more messages when doing PaulHSCData(legacy=FALSE)
with scRNAseq 2.17.5. Thanks @LTLA!
@vjcitn This can be closed.
seen on windows and linux