x <- array(1:27, c(3,3,3))
f <- tempfile()
# No data written to the file, hence invalid
io_h5_valid(f, 'r')
io_write_h5(x, f, 'dset')
io_h5_valid(f, 'w')
# Open the file and hold a connection
ptr <- hdf5r::H5File$new(filename = f, mode = 'w')
# Can read, but cannot write
io_h5_valid(f, 'r') # TRUE
io_h5_valid(f, 'w') # FALSE
# However, this can be reset via `close_all=TRUE`
io_h5_valid(f, 'r', close_all = TRUE)
io_h5_valid(f, 'w') # TRUE
# Now the connection is no longer valid
ptr
# clean up
unlink(f)
Run the code above in your browser using DataLab