rformassspectrometry / Spectra

Low level infrastructure to handle MS spectra
https://rformassspectrometry.github.io/Spectra/
34 stars 24 forks source link

Spectra serialisation #127

Open lgatto opened 3 years ago

lgatto commented 3 years ago

This issue was briefly mentioned in #124.

I think we need a way to serialise Spectra objects. This is trivial for in memory backends - the usual save() and load() apply - but not so for on disk backends.

But this starts to indicate that we might have to handle backends on a case by case basis. So instead of using the generic save()/load() (or equivalent RDS variants), I suggest that we have a dedicated method that will delegate the backend specificity to the object's backend. For example

setMethod("saveSpectra", 
   function(object, file, ...) {
    ## any backend specific preparation
    saveRDS(object, file = file, ...)
})

and

setMethod("loadSpectra",
  function(file, ...) {
    object <- readRDS(file) 
    ## verification/operations on object@backend
    return(object)
})