View source: R/write_h5files.R
write_h5files | R Documentation |
This function facilitates the progress of converting any R object into .h5 file to store information and read it in Python easily.
write_h5files(data, file_path = NULL)
.write_h5files(h5file, data, name = NULL)
data |
The data remain to be write |
file_path |
The file path of the h5file. Default is NULL and h5 file will be generated automatically |
h5file |
A new h5 file |
name |
Default is NULL. One of the names of a list. |
An h5 file
# Generate a matrix
set.seed(1)
ref_data <- matrix(rpois(n = 10^4, lambda = 0.5), nrow = 1000)
colnames(ref_data) <- paste0("cell_", 1:ncol(ref_data))
rownames(ref_data) <- paste0("gene_", 1:nrow(ref_data))
# Generate a sparse matrix
sparse_matrix <- Matrix::Matrix(data = ref_data, sparse = TRUE)
# Generate a dataframe
df <- as.data.frame(sparse_matrix)
# Generate a list
x <- list("length" = 2,
"integer" = 2L,
"logical" = TRUE,
"sparse_matrix" = sparse_matrix,
"df" = df,
"matrix" = ref_data)
# Set a path
file_path <- tempfile(fileext = ".h5")
# Write an h5 file
write_h5files(x, file_path = file_path)
# Load the h5 file
file.h5 <- hdf5r::H5File$new(file_path, mode = "r")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.