From 7fb4b0aed2a18b696abe54527e10a3616e25ae53 Mon Sep 17 00:00:00 2001 From: Ethan Bass Date: Tue, 27 Feb 2024 22:38:32 -0500 Subject: [PATCH] fix: bug in export_cdfs to permit conversion of files lacking metadata such as CSVs --- NEWS.md | 1 + R/write_chroms.R | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8f5084b..aa26bf3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ * Added support for 'Shimadzu ascii' files with '[LC Chromatogram...]' sub-header. * Correct 'Shimadzu ascii' chromatograms by 'Intensity Multiplier' if it is provided. * Minor, cosmetic changes to documentation. +* Fixed bug in logic in `export_cdfs` function to permit conversion of files lacking metadata. ## chromConverter 0.6.0 diff --git a/R/write_chroms.R b/R/write_chroms.R index 410b13b..d64f7f6 100644 --- a/R/write_chroms.R +++ b/R/write_chroms.R @@ -49,9 +49,14 @@ write_cdf <- function(x, path_out, sample_name, lambda = NULL, force = FALSE){ stop("Sample name must be provided.") } } - if (is.null(lambda) && ncol(x) + as.numeric(attr(x, "data_format") == "wide") > 2){ + if (is.null(attr(x,"data_format"))){ + is_long <- is.null(rownames(x)) || all(rownames(x) == seq_len(nrow(x))) + attr(x, "data_format") <- ifelse(is_long, "long", "wide") + } + if (is.null(lambda) && ncol(x) > 1 && attr(x, "data_format") == "wide") { warning("The supplied chromatogram contains more than two dimensions. Only - the first two dimensions will be written to the ANDI chrom file.", + the retention times and the first column of data will be written to + the ANDI chrom file.", immediate. = TRUE) } lambda <- ifelse(is.null(lambda), 1, lambda) @@ -135,7 +140,9 @@ format_metadata_for_cdf <- function(x){ # datetime_standard <- as.POSIXct(datetime_str, format = "%d.%m.%Y %H:%M:%S") datetime <- format(attr(x, "run_datetime"), "%Y%m%d%H%M%S%z") # rt_units <- x[which(x$Group=="Interval Time" & x$Property == "Units"), "Value"] - rt_units <- switch(tolower(attr(x, "time_unit")), + rt_units <- attr(x, "time_unit") + rt_units <- ifelse(!is.null(rt_units), tolower(rt_units), NA) + rt_units <- switch(tolower(rt_units), "sec" = "Seconds", "seconds" = "Seconds", "min" = "Minutes", "minutes" = "Minutes", "default" = "Minutes")