Skip to content

Commit 7fb4b0a

Browse files
committed
fix: bug in export_cdfs
to permit conversion of files lacking metadata such as CSVs
1 parent 1447f2f commit 7fb4b0a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Added support for 'Shimadzu ascii' files with '[LC Chromatogram...]' sub-header.
44
* Correct 'Shimadzu ascii' chromatograms by 'Intensity Multiplier' if it is provided.
55
* Minor, cosmetic changes to documentation.
6+
* Fixed bug in logic in `export_cdfs` function to permit conversion of files lacking metadata.
67

78
## chromConverter 0.6.0
89

R/write_chroms.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ write_cdf <- function(x, path_out, sample_name, lambda = NULL, force = FALSE){
4949
stop("Sample name must be provided.")
5050
}
5151
}
52-
if (is.null(lambda) && ncol(x) + as.numeric(attr(x, "data_format") == "wide") > 2){
52+
if (is.null(attr(x,"data_format"))){
53+
is_long <- is.null(rownames(x)) || all(rownames(x) == seq_len(nrow(x)))
54+
attr(x, "data_format") <- ifelse(is_long, "long", "wide")
55+
}
56+
if (is.null(lambda) && ncol(x) > 1 && attr(x, "data_format") == "wide") {
5357
warning("The supplied chromatogram contains more than two dimensions. Only
54-
the first two dimensions will be written to the ANDI chrom file.",
58+
the retention times and the first column of data will be written to
59+
the ANDI chrom file.",
5560
immediate. = TRUE)
5661
}
5762
lambda <- ifelse(is.null(lambda), 1, lambda)
@@ -135,7 +140,9 @@ format_metadata_for_cdf <- function(x){
135140
# datetime_standard <- as.POSIXct(datetime_str, format = "%d.%m.%Y %H:%M:%S")
136141
datetime <- format(attr(x, "run_datetime"), "%Y%m%d%H%M%S%z")
137142
# rt_units <- x[which(x$Group=="Interval Time" & x$Property == "Units"), "Value"]
138-
rt_units <- switch(tolower(attr(x, "time_unit")),
143+
rt_units <- attr(x, "time_unit")
144+
rt_units <- ifelse(!is.null(rt_units), tolower(rt_units), NA)
145+
rt_units <- switch(tolower(rt_units),
139146
"sec" = "Seconds", "seconds" = "Seconds",
140147
"min" = "Minutes", "minutes" = "Minutes",
141148
"default" = "Minutes")

0 commit comments

Comments
 (0)