Skip to content

Commit

Permalink
fix: bug in export_cdfs
Browse files Browse the repository at this point in the history
to permit conversion of files lacking metadata such as CSVs
  • Loading branch information
ethanbass committed Feb 28, 2024
1 parent 1447f2f commit 7fb4b0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 10 additions & 3 deletions R/write_chroms.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 7fb4b0a

Please sign in to comment.