Skip to content

Commit

Permalink
add reading siMPle formated spectra
Browse files Browse the repository at this point in the history
  • Loading branch information
wincowgerDEV committed Aug 27, 2024
1 parent 89fd435 commit f0d5e20
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/read_ext.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ read_text <- function(file, colnames = NULL, method = "fread",
if (all(grepl("^X[0-9]*", names(dt))))
stop("missing header: use 'header = FALSE' or an alternative read method",
call. = F)
if(sum(grepl("^[0-9]{1,}$",colnames(dt))) > 4) {
#This is for the siMPle csv format.
if(sum(c("WaveNumber", "Raw spectrum", "1st derivative", "2nd derivative") %in% names(dt)) > 2){
dt <- as.data.table(lapply(dt, as.numeric))
wavenumbers <- dt[["WaveNumber"]]
spectra <- dt[,-"WaveNumber"]
os <- as_OpenSpecy(x = as.numeric(wavenumbers), spectra = spectra,
metadata = metadata)
}
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])
metadata_names <- colnames(dt)[!grepl("^[0-9]{1,}$",colnames(dt))]
Expand Down

0 comments on commit f0d5e20

Please sign in to comment.