diff --git a/R/read_ext.R b/R/read_ext.R index 8db2175c..7fb46edd 100644 --- a/R/read_ext.R +++ b/R/read_ext.R @@ -5,7 +5,7 @@ #' @description #' Functions for reading spectral data from external file types. #' Currently supported reading formats are .csv and other text files, .asp, -#' .spa, .spc, and .jdx. +#' .spa, .spc, .xyz, and .jdx. #' Additionally, .0 (OPUS) and .dat (ENVI) files are supported via #' \code{\link{read_opus}()} and \code{\link{read_envi}()}, respectively. #' \code{\link{read_zip}()} takes any of the files listed above. @@ -98,6 +98,14 @@ read_text <- function(file, colnames = NULL, method = "fread", os <- as_OpenSpecy(x = as.numeric(wavenumbers), spectra = spectra, metadata = metadata) } + else if(grepl("\\.xyz$", basename(file), ignore.case = T)){ + wavenumbers <- as.numeric(dt[1, ])[-c(1:2)] + # Remove the first row + xy <- dt[-1,1:2] + colnames(xy) <- c("x", "y") + dt <- transpose(dt[-1, -c(1:2)]) + os <- as_OpenSpecy(x = wavenumbers, spectra = dt, metadata = xy) + } else if(sum(grepl("^[0-9]{1,}$",colnames(dt))) > 4) { wavenumbers <- colnames(dt)[grepl("^[0-9]{1,}$",colnames(dt))] spectra <- transpose(dt[,wavenumbers, with = FALSE]) diff --git a/R/read_multi.R b/R/read_multi.R index aa9d4e76..2428589d 100644 --- a/R/read_multi.R +++ b/R/read_multi.R @@ -52,7 +52,7 @@ read_any <- function(file, ...) { else if (grepl("(\\.zip$)", ignore.case = T, file)) { os <- read_zip(file = file, ...) } - else if (grepl("(\\.csv$)|(\\.tsv$)|(\\.txt$)", ignore.case = T, file)) { + else if (grepl("(\\.xyz$)|(\\.csv$)|(\\.tsv$)|(\\.txt$)", ignore.case = T, file)) { os <- read_text(file = file, ...) } else if (grepl("\\.[0-999]$", ignore.case = T, file)) { os <- read_opus(file = file, ...) diff --git a/man/read_ext.Rd b/man/read_ext.Rd index 60601518..c73914cd 100644 --- a/man/read_ext.Rd +++ b/man/read_ext.Rd @@ -123,7 +123,7 @@ named \code{"wavenumber"} and \code{"intensity"}. \description{ Functions for reading spectral data from external file types. Currently supported reading formats are .csv and other text files, .asp, -.spa, .spc, and .jdx. +.spa, .spc, .xyz, and .jdx. Additionally, .0 (OPUS) and .dat (ENVI) files are supported via \code{\link{read_opus}()} and \code{\link{read_envi}()}, respectively. \code{\link{read_zip}()} takes any of the files listed above.