diff --git a/DESCRIPTION b/DESCRIPTION index 73d20b9c..7c88df80 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: SeuratObject Type: Package Title: Data Structures for Single Cell Data -Version: 5.0.0.9002 +Version: 5.0.0.9003 Authors@R: c( person(given = 'Rahul', family = 'Satija', email = 'rsatija@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0001-9448-8833')), person(given = 'Paul', family = 'Hoffman', email = 'seurat@nygenome.org', role = c('aut', 'cre'), comment = c(ORCID = '0000-0002-7693-8957')), diff --git a/NEWS.md b/NEWS.md index 20761c1e..f8cef255 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ## Changes: - Update internal calls to `GetAssayData()` to use `layer` instead of `slot` (#160) +- Change layer-saving in `SaveSeuratRds()` to move all layers instead of just those in `tempdir()` (#169) # SeuratObject 5.0.0 ## Added diff --git a/R/seurat.R b/R/seurat.R index 1e5e2921..77853363 100644 --- a/R/seurat.R +++ b/R/seurat.R @@ -610,8 +610,8 @@ RenameAssays <- function( #' @param object A \code{\link{Seurat}} object #' @param file Path to save \code{object} to; defaults to #' \code{file.path(getwd(), paste0(Project(object), ".Rds"))} -#' @param destdir Destination directory for on-disk layers saved in -#' \dQuote{\code{\Sexpr[stage=render]{tempdir()}}} +#' @param move Move on-disk layers into \code(dirname(file)) +#' @param destdir \Sexpr[stage=build,results=rd]{lifecycle::badge("deprecated")} #' @param relative Save relative paths instead of absolute ones #' @inheritDotParams base::saveRDS #' @@ -685,12 +685,28 @@ RenameAssays <- function( SaveSeuratRds <- function( object, file = NULL, - destdir = NULL, + move = TRUE, + destdir = deprecated(), relative = FALSE, ... ) { file <- file %||% file.path(getwd(), paste0(Project(object = object), '.Rds')) file <- normalizePath(path = file, winslash = '/', mustWork = FALSE) + if (is_present(arg = destdir)) { + .Deprecate( + when = '5.0.1', + what = 'SaveSeuratRds(destdir = )', + with = 'SaveSeuratRds(move = )', + details = paste( + "Specifying a directory to move on-disk layers stored in", + sQuote(x = normalizePath(path = tempdir(), winslash = '/', mustWork = FALSE)), + "is deprecated; now, specify `move = TRUE` either move all on-disk layers to", + sQuote(x = dirname(path = file)), + "or `move = FALSE` leave them as-is" + ) + ) + move <- is_bare_character(x = destdir, n = 1L) || is.null(x = destdir) + } # Cache v5 assays assays <- .FilterObjects(object = object, classes.keep = 'StdAssay') p <- progressor(along = assays, auto_finish = TRUE) @@ -706,13 +722,9 @@ SaveSeuratRds <- function( ) cache <- vector(mode = 'list', length = length(x = assays)) names(x = cache) <- assays - tdir <- normalizePath(path = tempdir(), winslash = '/') # because macOS is weird - destdir <- destdir %||% dirname(path = file) - if (!is_na(x = destdir) || isTRUE(x = relative)) { - check_installed( - pkg = 'fs', - reason = 'for moving on-disk matrices' - ) + destdir <- dirname(path = file) + if (isTRUE(x = move)) { + check_installed(pkg = 'fs', reason = 'for moving on-disk matrices') } for (assay in assays) { p( @@ -746,27 +758,23 @@ SaveSeuratRds <- function( p(message = "No on-disk layers found", class = 'sticky', amount = 0) next } - if (!is_na(x = destdir)) { + if (isTRUE(x = move)) { for (i in seq_len(length.out = nrow(x = df))) { pth <- df$path[i] - mv <- substr(x = pth, start = 1L, stop = nchar(x = tdir)) == tdir || - isTRUE(x = relative) - if (isTRUE(x = mv)) { - p( - message = paste( - "Moving layer", - sQuote(x = df$layer[i]), - "to", - sQuote(x = destdir) - ), - class = 'sticky', - amount = 0 - ) - df[i, 'path'] <- as.character(x = .FileMove( - path = pth, - new_path = destdir - )) - } + p( + message = paste( + "Moving layer", + sQuote(x = df$layer[i]), + "to", + sQuote(x = destdir) + ), + class = 'sticky', + amount = 0 + ) + df[i, 'path'] <- as.character(x = .FileMove( + path = pth, + new_path = destdir + )) } } if (isTRUE(x = relative)) { diff --git a/R/utils.R b/R/utils.R index d4b7e691..2fb732f2 100644 --- a/R/utils.R +++ b/R/utils.R @@ -2276,7 +2276,11 @@ StitchMatrix.matrix <- function(x, y, rowmap, colmap, ...) { new_path <- fs::path_expand(path = new_path) new_path <- fs::dir_create(path = new_path) dest <- tryCatch( - expr = fs::dir_copy(path = path, new_path = new_path, overwrite = overwrite), + expr = fs::dir_copy( + path = path, + new_path = new_path, + overwrite = overwrite + ), EEXIST = eexist, error = hndlr ) @@ -2292,10 +2296,13 @@ StitchMatrix.matrix <- function(x, y, rowmap, colmap, ...) { ) } else { abort( - message = paste0( - "Can't find path: ", - sQuote(x = path), - "; if path is relative, change working directory." + message = paste( + strwrap(x = paste0( + "Can't find path: ", + sQuote(x = path), + "; if path is relative, change working directory" + )), + sep = '\n' ), call = caller_env(n = 1L + n) ) diff --git a/man/SaveSeuratRds.Rd b/man/SaveSeuratRds.Rd index 8d0fa921..24ad68cc 100644 --- a/man/SaveSeuratRds.Rd +++ b/man/SaveSeuratRds.Rd @@ -5,7 +5,14 @@ \alias{LoadSeuratRds} \title{Save and Load \code{Seurat} Objects from Rds files} \usage{ -SaveSeuratRds(object, file = NULL, destdir = NULL, relative = FALSE, ...) +SaveSeuratRds( + object, + file = NULL, + move = TRUE, + destdir = deprecated(), + relative = FALSE, + ... +) LoadSeuratRds(file, ...) } @@ -15,8 +22,9 @@ LoadSeuratRds(file, ...) \item{file}{Path to save \code{object} to; defaults to \code{file.path(getwd(), paste0(Project(object), ".Rds"))}} -\item{destdir}{Destination directory for on-disk layers saved in -\dQuote{\code{\Sexpr[stage=render]{tempdir()}}}} +\item{move}{Move on-disk layers into \code(dirname(file))} + +\item{destdir}{\Sexpr[stage=build,results=rd]{lifecycle::badge("deprecated")}} \item{relative}{Save relative paths instead of absolute ones}