I've been really enjoying working with Hyperspec with Horiba data. However, I'm now working with data from a custom instrument that has two main file types that I've been having difficulty reading in.
In both cases the samples (each a single spectrum) are in columns. The first column is the wavelength. In one case the file has a header (wavelength, sample 1, sample 2, ... ), the other file has no header. Both files are "," delimited. In this specific case, there is no spatial information associated with the data. However, I would like to treat the data as though the data were collected in a line such that the column index - 1 (first column is wavelength) is treated as an x-coordinate and y always = 1.
I've tried several versions of read.txt.long
and read.txt.wide
, a modified version of:
file <- read.table ("txt.t/Triazine 5_31.txt", header = TRUE, dec = ",", sep = "\t")
triazine <- new ("hyperSpec", wavelength = file [,1], spc = t (file [, -1]), data = data.frame (sample = colnames (file [, -1])),labels = list (.wavelength = "cm-1", spc = "I"))
and
wave_file <- "t100_UC.txt"
wave_intensities <- read_delim(wave_file, "/,")
new ("hyperSpec", spc = wave_intensities)
I'm fairly new to R and hyperspec, so I'm probably missing something obvious.
The errors I receive are:
Error in validObject(.Object) :
invalid class “hyperSpec” object: Length of wavelength vector differs from number of data points per spectrum.
In addition: Warning messages:
1: In .local(.Object, ...) : NAs introduced by coercion
2: In .local(.Object, ...) : spectra matrix is not numeric but matrix.