0

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.

lmo
  • 37,904
  • 9
  • 56
  • 69
Haley Sapers
  • 103
  • 10
  • Whatever this means "Length of wavelength vector differs from number of data points per spectrum" is the main source of the problem. It seems to imply that some function wants the number of values "per spectrum." The second warning might imply that the spc argument expects a vector rather, but was given a matrix. I am not familiar with this package, but the messages imply that you should compare the structure of the example data that you have been using with the structure of the novel data. `str` is one of my favorites for this. Compare structures for each argument. – lmo Mar 02 '18 at 22:46
  • Thank you very much - yes, upon inspection of my raw data there are 'tabs' masquerading as spaces so that not all of data was imported and the number of intensity values did not equal the number of wavelength values – Haley Sapers Mar 04 '18 at 07:22

0 Answers0