Learn R Programming

ieegio (version 0.0.4)

io_h5_valid: Check whether a 'HDF5' file can be opened for read/write

Description

Check whether a 'HDF5' file can be opened for read/write

Usage

io_h5_valid(file, mode = c("r", "w"), close_all = FALSE)

io_h5_names(file)

Value

io_h5_valid returns a logical value indicating whether the file can be opened. io_h5_names returns a character vector of dataset names.

Arguments

file

path to file

mode

'r' for read access and 'w' for write access

close_all

whether to close all connections or just close current connection; default is false. Set this to TRUE if you want to close all other connections to the file

Examples

Run this code

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