meireles / spectrolab

Dealing with spectral data in R
16 stars 11 forks source link

Subset spectra when sample names are numeric #1

Closed meireles closed 6 years ago

meireles commented 6 years ago

Subsetting spectra with integer names is very confusing! Check this out:

library(spectrolab)
x = as.spectra(spec_matrix_example[1:5, ])
names(x) = c(1,1,1,2,3)

# Now, one cannot access the 1st spectrum because the two subset statements below are equivalent
identical(x[1, ], x["1", ])

# Even worse, these two statements return the last spectrum!
identical(x[3, ], x[5, ])

I could differentiate between quoted (char) and unquoted (int) arguments, but that also seems confusing. I could simply force sample names to be char.

meireles commented 6 years ago

Fixed in the "develop" branch. See commits 5c5cfe7 to 59a4f6c. The spectra constructor and names setter do not allow names that are coercible to numeric. If given a numeric, the ctor adds a prefix.