Skip to content

Commit

Permalink
Add overwrite argument to write_h5ad()
Browse files Browse the repository at this point in the history
Error if file exists and overwrite = FALSE

Fixes #121
  • Loading branch information
lazappi committed Dec 5, 2023
1 parent 83e5c42 commit 7f02521
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion R/write_h5ad.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @param compression The compression algorithm to use when writing the
#' HDF5 file. Can be one of `"none"`, `"gzip"` or `"lzf"`. Defaults to
#' `"none"`.
#' @param overwrite Whether or not to overwrite `path` if it already exists
#'
#' @return `path` invisibly
#' @export
Expand Down Expand Up @@ -67,7 +68,13 @@
#' # h5ad_file <- tempfile(fileext = ".h5ad")
#' # write_h5ad(obj, h5ad_file)
#' }
write_h5ad <- function(object, path, compression = c("none", "gzip", "lzf")) {
write_h5ad <- function(object, path, compression = c("none", "gzip", "lzf"),
overwrite = FALSE) {

if (file.exists(path) && !overwrite) {
stop("'", path, "' already exists, set `overwrite = TRUE` to overwrite this file")
}

if (inherits(object, "SingleCellExperiment")) {
from_SingleCellExperiment(
object,
Expand Down

0 comments on commit 7f02521

Please sign in to comment.