diff --git a/R/process_spectra.R b/R/process_spectra.R index 231339d..bfd9afe 100644 --- a/R/process_spectra.R +++ b/R/process_spectra.R @@ -16,7 +16,7 @@ #' #' @param spectra_list A list of [MALDIquant::MassSpectrum] objects. #' @param spectra_names A [tibble::tibble] (or [data.frame]) of sanitized spectra names by default from [get_spectra_names]. If provided manually, the column `sanitized_name` will be used to name the spectra. -#' @param rds_prefix A character indicating the prefix for the `.RDS` output files to be written in the `processed` directory. By default, no prefix are given and thus no files are written. +#' @param rds_prefix `r lifecycle::badge('deprecated')` Writing to disk as RDS is no longer supported. A character indicating the prefix for the `.RDS` output files to be written in the `processed` directory. By default, no prefix are given and thus no files are written. #' #' @return A named list of three objects: #' * `spectra`: a list the length of the spectra list of [MALDIquant::MassSpectrum] objects. @@ -48,9 +48,16 @@ #' processed$metadata process_spectra <- function(spectra_list, spectra_names = get_spectra_names(spectra_list), - rds_prefix = NULL) { + rds_prefix = deprecated()) { # It returns the list and write it for future processing as an RDS file. + if (lifecycle::is_present(rds_prefix)) { + lifecycle::deprecate_warn( + when = "1.2.9000", + what = "process_spectra(rds_prefix)", + details = "Ability to write processed spectra to disk as RDS files will be dropped in next release." + ) + } # 1. SQRT transformation # 2. Mass range trimming # 3. Signal smoothing @@ -85,14 +92,14 @@ process_spectra <- function(spectra_list, ) # Add the spectra identifiers to all objects - if(! "sanitized_name" %in% colnames(spectra_names)){ + if (!"sanitized_name" %in% colnames(spectra_names)) { stop( "Missing 'sanitized_name' column in the provided 'spectra_names' tibble!", "\n\nTip: Use the `get_spectra_names()` for default and compliant names." ) } rownames(metadata) <- names(spectra) <- names(peaks) <- spectra_names[["sanitized_name"]] - + # Aggregate the objects to a list processed_list <- list( "spectra" = spectra, @@ -101,15 +108,5 @@ process_spectra <- function(spectra_list, "metadata" = tibble::as_tibble(metadata, rownames = "name") ) - # Optional: writing objects to RDS files - if (!is.null(rds_prefix)) { - if (!dir.exists("processed")) { - dir.create("processed") - } - saveRDS(processed_list, - version = 2, compress = FALSE, - file = paste0("processed/", rds_prefix, ".RDS") - ) - } return(processed_list) } diff --git a/dev/dereplicate-spectra.Rmd b/dev/dereplicate-spectra.Rmd index 2d80ec5..94a6f5e 100644 --- a/dev/dereplicate-spectra.Rmd +++ b/dev/dereplicate-spectra.Rmd @@ -57,7 +57,7 @@ The full procedure is illustrated in the example below. While in this case, all #' #' @param spectra_list A list of [MALDIquant::MassSpectrum] objects. #' @param spectra_names A [tibble::tibble] (or [data.frame]) of sanitized spectra names by default from [get_spectra_names]. If provided manually, the column `sanitized_name` will be used to name the spectra. -#' @param rds_prefix A character indicating the prefix for the `.RDS` output files to be written in the `processed` directory. By default, no prefix are given and thus no files are written. +#' @param rds_prefix `r lifecycle::badge('deprecated')` Writing to disk as RDS is no longer supported. A character indicating the prefix for the `.RDS` output files to be written in the `processed` directory. By default, no prefix are given and thus no files are written. #' #' @return A named list of three objects: #' * `spectra`: a list the length of the spectra list of [MALDIquant::MassSpectrum] objects. @@ -73,9 +73,16 @@ The full procedure is illustrated in the example below. While in this case, all #' @examples process_spectra <- function(spectra_list, spectra_names = get_spectra_names(spectra_list), - rds_prefix = NULL) { + rds_prefix = deprecated()) { # It returns the list and write it for future processing as an RDS file. + if (lifecycle::is_present(rds_prefix)) { + lifecycle::deprecate_warn( + when = "1.2.9000", + what = "process_spectra(rds_prefix)", + details = "Ability to write processed spectra to disk as RDS files will be dropped in next release." + ) + } # 1. SQRT transformation # 2. Mass range trimming # 3. Signal smoothing @@ -110,14 +117,14 @@ process_spectra <- function(spectra_list, ) # Add the spectra identifiers to all objects - if(! "sanitized_name" %in% colnames(spectra_names)){ + if (!"sanitized_name" %in% colnames(spectra_names)) { stop( "Missing 'sanitized_name' column in the provided 'spectra_names' tibble!", "\n\nTip: Use the `get_spectra_names()` for default and compliant names." ) } rownames(metadata) <- names(spectra) <- names(peaks) <- spectra_names[["sanitized_name"]] - + # Aggregate the objects to a list processed_list <- list( "spectra" = spectra, @@ -126,16 +133,6 @@ process_spectra <- function(spectra_list, "metadata" = tibble::as_tibble(metadata, rownames = "name") ) - # Optional: writing objects to RDS files - if (!is.null(rds_prefix)) { - if (!dir.exists("processed")) { - dir.create("processed") - } - saveRDS(processed_list, - version = 2, compress = FALSE, - file = paste0("processed/", rds_prefix, ".RDS") - ) - } return(processed_list) } ``` diff --git a/man/figures/lifecycle-deprecated.svg b/man/figures/lifecycle-deprecated.svg new file mode 100755 index 0000000..b61c57c --- /dev/null +++ b/man/figures/lifecycle-deprecated.svg @@ -0,0 +1,21 @@ + + lifecycle: deprecated + + + + + + + + + + + + + + + lifecycle + + deprecated + + diff --git a/man/process_spectra.Rd b/man/process_spectra.Rd index e018d25..77b2d4b 100644 --- a/man/process_spectra.Rd +++ b/man/process_spectra.Rd @@ -7,7 +7,7 @@ process_spectra( spectra_list, spectra_names = get_spectra_names(spectra_list), - rds_prefix = NULL + rds_prefix = deprecated() ) } \arguments{ @@ -15,7 +15,7 @@ process_spectra( \item{spectra_names}{A \link[tibble:tibble]{tibble::tibble} (or \link{data.frame}) of sanitized spectra names by default from \link{get_spectra_names}. If provided manually, the column \code{sanitized_name} will be used to name the spectra.} -\item{rds_prefix}{A character indicating the prefix for the \code{.RDS} output files to be written in the \code{processed} directory. By default, no prefix are given and thus no files are written.} +\item{rds_prefix}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Writing to disk as RDS is no longer supported. A character indicating the prefix for the \code{.RDS} output files to be written in the \code{processed} directory. By default, no prefix are given and thus no files are written.} } \value{ A named list of three objects: