SaveSeuratRds {SeuratObject} | R Documentation |
Save and Load Seurat
Objects from Rds files
Description
Save and Load Seurat
Objects from Rds files
Usage
SaveSeuratRds(
object,
file = NULL,
move = TRUE,
destdir = deprecated(),
relative = FALSE,
...
)
LoadSeuratRds(file, ...)
Arguments
object |
A |
file |
Path to save |
move |
Move on-disk layers into |
destdir |
|
relative |
Save relative paths instead of absolute ones |
... |
Arguments passed on to
|
Value
Invisibly returns file
Progress Updates with progressr
This function uses
progressr to
render status updates and progress bars. To enable progress updates, wrap
the function call in with_progress
or run
handlers(global = TRUE)
before running
this function. For more details about progressr, please read
vignette("progressr-intro")
Note
This function requires the fs package to be installed
See Also
Examples
if (requireNamespace("fs", quietly = TRUE)) {
# Write out with DelayedArray
if (requireNamespace("HDF5Array", quietly = TRUE)) {
pbmc <- pbmc_small
pbmc[["disk"]] <- CreateAssay5Object(list(
mem = LayerData(pbmc, "counts"),
disk = as(LayerData(pbmc, "counts"), "HDF5Array")
))
# Save `pbmc` to an Rds file
out <- tempfile(fileext = ".Rds")
SaveSeuratRds(pbmc, file = out)
# Object cache
obj <- readRDS(out)
Tool(obj, "SaveSeuratRds")
# Load the saved object with on-disk layers back into memory
pbmc2 <- LoadSeuratRds(out)
pbmc2
pbmc2[["disk"]]
}
# Write out with BPCells
if (requireNamespace("BPCells", quietly = TRUE)) {
pbmc <- pbmc_small
bpm <- BPCells::write_matrix_dir(LayerData(pbmc, "counts"), dir = tempfile())
bph <- BPCells::write_matrix_hdf5(
LayerData(pbmc, "counts"),
path = tempfile(fileext = ".h5"),
group = "counts"
)
pbmc[["disk"]] <- CreateAssay5Object(list(dir = bpm, h5 = bph))
# Save `pbmc` to an Rds file
out <- tempfile(fileext = ".Rds")
SaveSeuratRds(pbmc, file = out)
# Object cache
obj <- readRDS(out)
Tool(obj, "SaveSeuratRds")
# Load the saved object with on-disk layers back into memory
pbmc2 <- LoadSeuratRds(out)
pbmc2
pbmc2[["disk"]]
}
}