From 1c18870557716f2099401421095f8d8447626334 Mon Sep 17 00:00:00 2001 From: Ethan Bass Date: Sun, 24 Dec 2023 18:02:34 -0500 Subject: [PATCH] fix: windows path bug in lcd parser --- NEWS.md | 1 + R/read_shimadzu_lcd.R | 2 +- tests/testthat/test-extra.R | 17 ++++++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index 31d85fe..ce521b5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ * Added `...` argument to `read_chroms` for supplying additional arguments to parsers. * Added alias to `read_chroms` for reading `mzxml` files with `RaMS`. * Added `precision` argument to `call_rainbow` to control number of digits "mz" values are rounded to. (Also changed default behavior so values are rounded to one decimal by default). +* Fixed bug in `read_shimadzu_lcd` on Windows due to issue with passing escaped paths to Python. * Updated documentation of various functions. ## chromConverter 0.5.0 diff --git a/R/read_shimadzu_lcd.R b/R/read_shimadzu_lcd.R index b00239d..b7b4fb2 100644 --- a/R/read_shimadzu_lcd.R +++ b/R/read_shimadzu_lcd.R @@ -172,7 +172,7 @@ export_stream <- function(path_in, stream, path_out, remove_null_bytes = FALSE, reticulate::py_run_string('data = st.read()') if (missing(path_out)){ - path_out <- tempfile() + path_out <- fs::file_temp() } if (remove_null_bytes){ reticulate::py_run_string("data = data.replace(b'\\x00', b'')") diff --git a/tests/testthat/test-extra.R b/tests/testthat/test-extra.R index ee3f04b..9ecdd9d 100644 --- a/tests/testthat/test-extra.R +++ b/tests/testthat/test-extra.R @@ -295,27 +295,30 @@ test_that("read_peaklist can read `Shimadzu` ascii (PDA) files", { expect_equal(colnames(x[[1]]), c("sample", "rt", "start", "end", "area", "height")) }) -test_that("read_chroms can read 'Shimadzu' ascii (PDA) files", { +test_that("read_chroms can read 'Shimadzu' PDA files (ascii and LCD)", { skip_on_cran() skip_if_not_installed("chromConverterExtraTests") - path <- system.file("shimadzuDAD_Anthocyanin.txt", + path_ascii <- system.file("shimadzuDAD_Anthocyanin.txt", package = "chromConverterExtraTests") - skip_if_not(file.exists(path)) + skip_if_not(file.exists(path_ascii)) - x <- read_chroms(path, format_in = "shimadzu_dad", progress_bar = FALSE)[[1]] + path_lcd <- system.file("Anthocyanin.lcd", package = "chromConverterExtraTests") + skip_if_not(file.exists(path_lcd)) + + x <- read_chroms(path_ascii, format_in = "shimadzu_dad", progress_bar = FALSE)[[1]] expect_equal(class(x)[1], "matrix") expect_equal(dim(x), c(4689, 328)) expect_equal(attr(x, "parser"), "chromconverter") expect_equal(attr(x, "data_format"), "wide") - x1 <- read_chroms(path, format_in="shimadzu_dad", progress_bar = FALSE, + x1 <- read_chroms(path_ascii, format_in="shimadzu_dad", progress_bar = FALSE, data_format = "long", format_out = "data.frame")[[1]] expect_equal(class(x1)[1], "data.frame") expect_equal(dim(x1), c(4689*328, 3)) - path <- system.file("Anthocyanin.lcd", package = "chromConverterExtraTests") - x2 <- read_chroms(path, progress_bar = FALSE)[[1]] + + x2 <- read_chroms(path_lcd, progress_bar = FALSE)[[1]] expect_equal(dim(x2),c(4689,328)) expect_equal(x, x2, ignore_attr = TRUE) })