Skip to content

Commit

Permalink
add xyz file reading, working.
Browse files Browse the repository at this point in the history
  • Loading branch information
wincowgerDEV committed Sep 13, 2024
1 parent f0d5e20 commit 7cfac21
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion R/read_ext.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion R/read_multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down
2 changes: 1 addition & 1 deletion man/read_ext.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7cfac21

Please sign in to comment.