11
11
# ' @param read_metadata Whether to read metadata from file.
12
12
# ' @param metadata_format Format to output metadata. Either \code{chromconverter} or
13
13
# ' \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{","}.
14
17
# ' @return A chromatogram in the format specified by \code{format_out}.
15
18
# ' (retention time x wavelength).
16
19
# ' @author Ethan Bass
@@ -20,25 +23,31 @@ read_chromeleon <- function(path, format_out = c("matrix", "data.frame",
20
23
" data.table" ),
21
24
data_format = c(" wide" , " long" ),
22
25
read_metadata = TRUE ,
23
- metadata_format = c(" chromconverter" , " raw" )){
26
+ metadata_format = c(" chromconverter" , " raw" ),
27
+ decimal_mark = NULL ){
24
28
format_out <- check_format_out(format_out )
25
29
data_format <- match.arg(data_format , c(" wide" , " long" ))
26
30
metadata_format <- match.arg(metadata_format , c(" chromconverter" , " raw" ))
27
31
metadata_format <- switch (metadata_format , chromconverter = " chromeleon" ,
28
32
raw = raw )
33
+ if (! is.null(decimal_mark )){
34
+ decimal_mark <- match.arg(decimal_mark , c(" ." , " ," ))
35
+ }
29
36
xx <- readLines(path )
30
37
xx <- remove_unicode_chars(xx )
31
38
start <- tail(grep(" Data:" , xx ), 1 )
32
39
x <- read.csv(path , skip = start , sep = " \t " , row.names = NULL ,
33
40
check.names = FALSE )
34
41
x <- x [, - 2 , drop = FALSE ]
35
42
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 <- " ,"
38
46
x <- apply(x , 2 , function (x ) gsub(" \\ ." , " " , x ))
39
47
x <- apply(x , 2 , function (x ) gsub(" ," , " ." , x ))
40
48
} else {
41
- decimal_separator <- " ."
49
+ decimal_mark <- " ."
50
+ x <- apply(x , 2 , function (x ) gsub(" ," , " " , x ))
42
51
}
43
52
x <- apply(x , 2 , as.numeric )
44
53
if (ncol(x ) == 2 ){
@@ -55,8 +64,7 @@ read_chromeleon <- function(path, format_out = c("matrix", "data.frame",
55
64
}
56
65
x <- convert_chrom_format(x , format_out = format_out )
57
66
if (read_metadata ){
58
- meta <- try(read_chromeleon_metadata(xx ))
59
- if (decimal_separator == " ," ){
67
+ if (decimal_mark == " ," ){
60
68
meta <- lapply(meta , function (x ) gsub(" ," , " ." , x ))
61
69
}
62
70
if (! inherits(meta , " try-error" )){
0 commit comments