Skip to content

Commit 539c467

Browse files
committed
fix: long format output for read_shimadzu (ASCII files)
1 parent 385f5ae commit 539c467

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

R/read_shimadzu_ascii.R

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ read_shimadzu <- function(path, what = "chroms",
106106
xx
107107
})
108108
names(chroms) <- names(chrom.idx)
109-
if (data_format == "long"){
110-
# how to merge metadata appropriately?
111-
if (inherits(chroms[[1]], "list")){
112-
chroms <- unlist(chroms, recursive = FALSE)
113-
}
114-
chroms <- do.call(rbind, chroms)
109+
if (data_format == "long" && format_out != "matrix"){
110+
chroms <- lapply(chroms, function(det){
111+
if (inherits(det, "list")){
112+
do.call(rbind, det)
113+
} else det
114+
})
115115
}
116116
}
117117

@@ -239,15 +239,11 @@ read_shimadzu_chromatogram <- function(path, x, chrom.idx, sep, data_format,
239239
}
240240

241241
xx <- as.matrix(xx[!is.na(xx[, 1]), ])
242-
243-
if (data_format == "wide"){
244-
rownames(xx) <- xx[, 1]
245-
xx <- xx[, 2, drop = FALSE]
246-
colnames(xx) <- "Intensity"
247-
} else if (data_format == "long"){
248-
xx <- data.frame(rt = xx[,1], int = xx[,2],
249-
name = gsub("\\[|\\]", "", x[chrom.idx]),
250-
units = meta$`Intensity Units`)
242+
xx <- format_2d_chromatogram(rt = xx[,1], int = xx[,2], data_format = data_format,
243+
format_out = "data.frame")
244+
if (data_format == "long" && format_out != "matrix"){
245+
xx$name <- gsub("\\[|\\]", "", x[chrom.idx])
246+
xx$units <- meta$`Intensity Units`
251247
}
252248
xx <- convert_chrom_format(xx, format_out = format_out, data_format = data_format)
253249
if (read_metadata){

0 commit comments

Comments
 (0)