diff --git a/DESCRIPTION b/DESCRIPTION index 72f391f..05c287b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: isoreader Title: Read Stable Isotope Data Files Description: Interface to the raw data file formats commonly encountered in scientific disciplines that make use of stable isotopes. -Version: 1.4.1 +Version: 1.4.2 Authors@R: c(person( given = "Sebastian", family = "Kopf", diff --git a/R/utils_binary_isodat_files.R b/R/utils_binary_isodat_files.R index 36b9c04..99a6254 100644 --- a/R/utils_binary_isodat_files.R +++ b/R/utils_binary_isodat_files.R @@ -793,23 +793,34 @@ parse_raw_data <- function(raw, type, n = full_raw(), ignore_trailing_zeros = FA regexp <- sprintf("(%s){%.0f}", dbc[[1]]$regexp, n) if (length(grepRaw(regexp, raw_trim)) == 0) { # something that is NOT text is in the raw_trim - non_text_pos <- grepRaw("([\x20-\xff][\x01-\xff])|(\\x00\\x00)", raw_trim) - actual_text <- intToUtf8(raw_trim[1:(non_text_pos - 1)]) - if (!is.null(errors)) { - err_raw <- raw_trim[(non_text_pos + 1):length(raw_trim)] - stop( - sprintf("%sexpected unicode data for %.0f bytes but found only %.0f ('%s'), non-text raw data afterwards: %s", - error_prefix, n*2, non_text_pos, actual_text, - if (length(err_raw) > 10) - c(as.character(head(err_raw, 10)), sprintf("+%d more", length(err_raw) - 10)) |> - paste(collapse = " ") - else - as.character(err_raw) |> - paste(collapse = " ") - ), - call. = FALSE) + + # check for common extended unicode characters (micro) + ext_uni <- grepRaw("\xb5\xff", raw_trim) + if (length(ext_uni) > 0L) { + raw_trim[ext_uni + 1L] <- as.raw(00) + raw[ext_uni + 1L] <- as.raw(00) + } + + # check again if any extended unicodes were found + if (length(ext_uni) == 0L || length(grepRaw(regexp, raw_trim)) == 0) { + non_text_pos <- grepRaw("([\x20-\xff][\x01-\xff])|(\\x00\\x00)", raw_trim) + actual_text <- intToUtf8(raw_trim[1:(non_text_pos - 1)]) + if (!is.null(errors)) { + err_raw <- raw_trim[(non_text_pos + 1):length(raw_trim)] + stop( + sprintf("%sexpected unicode data for %.0f bytes but found only %.0f ('%s'), non-text raw data afterwards: %s", + error_prefix, n*2, non_text_pos, actual_text, + if (length(err_raw) > 10) + c(as.character(head(err_raw, 10)), sprintf("+%d more", length(err_raw) - 10)) |> + paste(collapse = " ") + else + as.character(err_raw) |> + paste(collapse = " ") + ), + call. = FALSE) + } + return(NULL) } - return(NULL) } } diff --git a/tests/testthat/test-continuous-flow.R b/tests/testthat/test-continuous-flow.R index 2314020..5625fd3 100644 --- a/tests/testthat/test-continuous-flow.R +++ b/tests/testthat/test-continuous-flow.R @@ -319,6 +319,28 @@ test_that("test that additional continous flow files can be read", { `Rps 46CO2/44CO2` = NA) ) + check_continuous_flow_test_file( + "dxf_example_C_02.dxf", + c("file_id", "file_root", "file_path", "file_subpath", "file_datetime", + "file_size", "Row", "Peak Center", "Check Ref. Dilution", "H3 Stability", + "H3 Factor", "AS Sample", "AS Method", "Identifier 1", "Identifier 2", + "Analysis", "Comment", "Preparation", "Method", "measurement_info", + "MS_integration_time.s"), + 15, + c(Nr. = NA, Start = "s", Rt = "s", End = "s", `Ampl 44` = "mV", `Ampl 45` = "mV", + `Ampl 46` = "mV", `BGD 44` = "mV", `BGD 45` = "mV", `BGD 46` = "mV", + `rIntensity 44` = "mVs", `rIntensity 45` = "mVs", `rIntensity 46` = "mVs", + `rIntensity All` = "mVs", `Intensity 44` = "Vs", `Intensity 45` = "Vs", + `Intensity 46` = "Vs", `Intensity All` = "Vs", + `Sample Dilution` = "%", `List First Peak` = NA, `rR 45CO2/44CO2` = NA, + `rR 46CO2/44CO2` = NA, `Is Ref.?` = NA, `R 45CO2/44CO2` = NA, `Ref. Name` = NA, + `rd 45CO2/44CO2` = "permil", `d 45CO2/44CO2` = "permil", `R 46CO2/44CO2` = NA, + `rd 46CO2/44CO2` = "permil", `d 46CO2/44CO2` = "permil", `R 13C/12C` = NA, + `d 13C/12C` = "permil", `AT% 13C/12C` = "%", `R 18O/16O` = NA, `d 18O/16O` = "permil", + `AT% 18O/16O` = "%", `R 17O/16O` = NA, `d 17O/16O` = NA, `Rps 45CO2/44CO2` = NA, + `Rps 46CO2/44CO2` = NA) + ) + check_continuous_flow_test_file( "dxf_example_CNS_01.dxf", c("file_id", "file_root", "file_path", "file_subpath", "file_datetime", diff --git a/tests/testthat/test_data/dxf_example_C_02.dxf b/tests/testthat/test_data/dxf_example_C_02.dxf new file mode 100644 index 0000000..4568419 Binary files /dev/null and b/tests/testthat/test_data/dxf_example_C_02.dxf differ