| h5_exists | R Documentation |
Safely checks if a file, an object within a file, or an attribute on an object exists.
h5_exists(file, name = "/", attr = NULL, assert = FALSE)
file |
Path to the file. |
name |
The full path of the object to check (e.g., |
attr |
The name of an attribute to check. If provided, the function tests
for the existence of this attribute on |
assert |
Logical. If |
This function provides a robust, error-free way to test for existence.
Testing for a File: If name is / and attr is NULL,
the function checks if file is a valid, readable HDF5 file.
Testing for an Object: If name is a path (e.g., /data/matrix)
and attr is NULL, the function checks if the specific object exists.
Testing for an Attribute: If attr is provided, the function checks
if that attribute exists on the specified object name.
A logical value: TRUE if the target exists and is valid, FALSE otherwise.
h5_is_group(), h5_is_dataset()
file <- tempfile(fileext = ".h5")
h5_exists(file) # FALSE
h5_create_file(file)
h5_exists(file) # TRUE
h5_exists(file, "missing_object") # FALSE
h5_write(1:10, file, "my_ints")
h5_exists(file, "my_ints") # TRUE
h5_exists(file, "my_ints", "missing_attr") # FALSE
h5_write(1:10, file, "my_ints", attr = "my_attr")
h5_exists(file, "my_ints", "my_attr") # TRUE
unlink(file)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.