r-hyperspec / hyperSpec

hyperSpec: Tools for Spectroscopy (R package)
https://r-hyperspec.github.io/hyperSpec/
GNU General Public License v3.0
12 stars 3 forks source link

dput(hyperSpec object) doesn't work #68

Closed cbeleites closed 2 years ago

cbeleites commented 2 years ago
dput(flu[1,,400~ 410])

gives:

new("hyperSpec", wavelength = c(405, 405.5, 406, 406.5, 407, 407.5, 408, 408.5, 409, 409.5, 410), 
    data = structure(list(spc = structure(c(27.15, 32.344666, 33.378666, 34.419333, 36.531333, 37.647666, 38.137, 
                                            39.177, 40.735666, 41.381333, 44.251333), .Dim = c(1L, 11L), .Dimnames = list(
                                              NULL, c("405", "405.5", "406", "406.5", "407", "407.5", "408", 
                                                      "408.5", "409", "409.5", "410"))), 
                          filename = "rawdata/flu1.txt", 
                          c = 0.05), row.names = 1L, class = "data.frame"), label = list(
                            .wavelength = expression(lambda/nm), spc = expression(I[fl]/"a.u."), 
                            filename = "filename", c = "c / (mg / l)"), 
    log = new("data.frame", 
              .Data = list(), names = character(0), row.names = integer(0), 
              .S3Class = "data.frame"))

Which throws an error due to trying to assign the log slot.

This prevents reprex() from working with user-supplied spectra

GegznaV commented 2 years ago

One of the solutions is to add a log argument to new("hyperSpec", ...), which is sued only for backward compatibility (i.e., not to break the result of dput()). In the future, this can be solved in a more systematic way.