Skip to content

Commit 2c5a93b

Browse files
committed
fix: bug in read_chromeleon (faulty inference of decimal separator)
1 parent fefefb0 commit 2c5a93b

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Updated `read_shimadzu_lcd` to infer retention times in Shimadzu 3D Data from `Max Plot` stream since it is always (?) present.
44
* Updated `read_shimadzu_lcd` to skip parsing of metadata from 3D Data Item when it is not present.
55
* Updated `read_shimadzu_lcd` to include `Max Plot` stream when parsing 2D chromatograms.
6+
* Fixed bug in `read_chromeleon` related to inference of decimal separators.
7+
* Added `decimal_mark` argument to `read_chromeleon` to manually set decimal separator.
68

79
## chromConverter 0.7.2
810

R/read_chromeleon.R

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#' @param read_metadata Whether to read metadata from file.
1212
#' @param metadata_format Format to output metadata. Either \code{chromconverter} or
1313
#' \code{raw}.
14+
#' @param decimal_mark Which character is used as the decimal separator in the
15+
#' file. By default, decimal mark will be detected automatically, but it can
16+
#' also be manually set as \code{"."} or \code{","}.
1417
#' @return A chromatogram in the format specified by \code{format_out}.
1518
#' (retention time x wavelength).
1619
#' @author Ethan Bass
@@ -20,25 +23,31 @@ read_chromeleon <- function(path, format_out = c("matrix", "data.frame",
2023
"data.table"),
2124
data_format = c("wide", "long"),
2225
read_metadata = TRUE,
23-
metadata_format = c("chromconverter", "raw")){
26+
metadata_format = c("chromconverter", "raw"),
27+
decimal_mark = NULL){
2428
format_out <- check_format_out(format_out)
2529
data_format <- match.arg(data_format, c("wide", "long"))
2630
metadata_format <- match.arg(metadata_format, c("chromconverter", "raw"))
2731
metadata_format <- switch(metadata_format, chromconverter = "chromeleon",
2832
raw = raw)
33+
if (!is.null(decimal_mark)){
34+
decimal_mark <- match.arg(decimal_mark, c(".", ","))
35+
}
2936
xx <- readLines(path)
3037
xx <- remove_unicode_chars(xx)
3138
start <- tail(grep("Data:", xx), 1)
3239
x <- read.csv(path, skip = start, sep = "\t", row.names = NULL,
3340
check.names = FALSE)
3441
x <- x[, -2, drop = FALSE]
3542
x <- x[, colSums(is.na(x)) < nrow(x)]
36-
if (any(grepl(",", as.data.frame(x)[-1, 2]))){
37-
decimal_separator <- ","
43+
meta <- try(read_chromeleon_metadata(xx))
44+
if (is.null(decimal_mark) && grepl(",", meta$`Dilution Factor`)){
45+
decimal_mark <- ","
3846
x <- apply(x, 2, function(x) gsub("\\.", "", x))
3947
x <- apply(x, 2, function(x) gsub(",", ".", x))
4048
} else {
41-
decimal_separator <- "."
49+
decimal_mark <- "."
50+
x <- apply(x, 2, function(x) gsub(",", "", x))
4251
}
4352
x <- apply(x, 2, as.numeric)
4453
if (ncol(x) == 2){
@@ -55,8 +64,7 @@ read_chromeleon <- function(path, format_out = c("matrix", "data.frame",
5564
}
5665
x <- convert_chrom_format(x, format_out = format_out)
5766
if (read_metadata){
58-
meta <- try(read_chromeleon_metadata(xx))
59-
if (decimal_separator == ","){
67+
if (decimal_mark == ","){
6068
meta <- lapply(meta, function(x) gsub(",", ".", x))
6169
}
6270
if (!inherits(meta, "try-error")){

man/read_chromeleon.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)