Skip to content

Commit b552d81

Browse files
committed
fix: check_data_format
1 parent 536fc20 commit b552d81

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

R/call_aston.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ uv_converter <- function(path, format_out = c("matrix","data.frame","data.table"
8686
if (data_format == "long"){
8787
x <- reshape_chrom(x, data_format = "long")
8888
}
89-
x <- convert_chrom_format(x, format_out = format_out)
89+
x <- convert_chrom_format(x, format_out = format_out, data_format)
9090
if (correction){
9191
# multiply by empirical correction value
9292
correction_value <- 0.9536743164062551070259132757200859487056732177734375
@@ -127,7 +127,7 @@ trace_converter <- function(path, format_out = c("matrix", "data.frame"),
127127
if (data_format == "long"){
128128
x <- reshape_chrom(x, data_format = "long")
129129
}
130-
x <- convert_chrom_format(x, format_out = format_out)
130+
x <- convert_chrom_format(x, format_out = format_out, data_format)
131131
x
132132
}
133133

R/call_entab.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ call_entab <- function(path, data_format = c("wide", "long"),
5151
colnames(x)[c(1, 3)] <- c("rt", "intensity")
5252
data_format <- "long"
5353
}
54-
x <- convert_chrom_format(x, format_out = format_out)
54+
x <- convert_chrom_format(x, format_out = format_out, data_format)
5555
if (read_metadata){
5656
meta <- r$metadata()
5757
meta$run_date <- as.POSIXct(eval(meta$run_date))

R/read_chemstation_csv.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ read_chemstation_csv <- function(path, format_out = c("matrix", "data.frame",
2727
data_format = c("wide", "long"),
2828
read_metadata = TRUE){
2929
format_out <- check_format_out(format_out)
30-
data_format <- match.arg(data_format, c("wide", "long"))
30+
data_format <- check_data_format(data_format, format_out = format_out)
3131
data <- read.csv(path, row.names = 1, header = TRUE,
3232
fileEncoding = "utf-16LE", check.names = FALSE)
3333

R/read_shimadzu_ascii.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ read_shimadzu <- function(path, what = "chroms",
6262
include <- match.arg(include, c("fid", "lc", "dad", "uv", "tic", "status"),
6363
several.ok = TRUE)
6464
format_out <- check_format_out(format_out)
65-
data_format <- match.arg(data_format, c("wide", "long"))
65+
data_format <- check_data_format(data_format, format_out)
6666
peaktable_format <- match.arg(peaktable_format, c("chromatographr", "original"))
6767
metadata_format <- match.arg(metadata_format, c("chromconverter", "raw"))
6868
ms_format <- match.arg(ms_format, c("data.frame", "list"))

R/utils.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ check_format_out <- function(format_out){
77
match.arg(format_out, c("matrix", "data.frame", "data.table"))
88
}
99

10+
#' Check Data Format Argument
11+
#'
12+
#' Make sure that \code{data_format} argument is "long" when \code{format_out} is
13+
#' \code{"data.table"}.
14+
#' @noRd
15+
16+
check_data_format <- function(data_format, format_out){
17+
if (format_out == "data.table"){
18+
data_format <- "long"
19+
}
20+
match.arg(data_format, c("wide", "long"))
21+
}
22+
1023
#' Convert chromatogram format
1124
#' @author Ethan Bass
1225
#' @noRd

tests/testthat/test-read_chroms.R

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test_that("chromConverter can read `Agilent Chemstation` .csv file", {
1717
x1 <- read_chroms(path_csv, format_in = "chemstation_csv",
1818
format_out = "data.table", progress_bar = FALSE)[[1]]
1919
expect_s3_class(x1, "data.table")
20-
expect_equal(colnames(x1), c("rt", "220.00000"))
20+
expect_equal(colnames(x1), c("rt", "intensity"))
2121
expect_equal(attr(x1, "data_format"), "long")
2222
expect_equal(attr(x1, "format_out"), "data.table")
2323

@@ -156,18 +156,16 @@ test_that("`Shimadzu` ASCII parser works", {
156156
expect_s3_class(x1, "data.table")
157157
expect_equal(attr(x1, "format_out"), "data.table")
158158
expect_equal(attr(x1, "data_format"), "long")
159-
expect_equal(dim(x1),c(66255,2))
159+
expect_equal(dim(x1),c(66255,3))
160160

161161
x2 <- read_chroms(path, format_in = "shimadzu_fid", find_files = FALSE,
162-
progress_bar = FALSE, format_out="data.frame")[[1]]
162+
progress_bar = FALSE, format_out="data.frame",
163+
data_format = "long")[[1]]
163164
expect_s3_class(x2, "data.frame")
164165
expect_equal(attr(x2, "format_out"), "data.frame")
165-
expect_equal(attr(x2, "data_format"), "wide")
166-
expect_equal(dim(x2),c(66255,1))
167-
expect_equal(x1,x2)
168-
169-
# long format doesn't work
170-
# maybe because there's nothing to add?
166+
expect_equal(attr(x2, "data_format"), "long")
167+
expect_equal(dim(x2),c(66255,3))
168+
expect_equal(x1, x2, ignore_attr=TRUE)
171169
})
172170

173171
test_that("read_mzml works", {

0 commit comments

Comments
 (0)