hector
hector copied to clipboard
Save Hector cores as R data
@ashiklom and I were talking about how for one of our projects were are going to need to set up lots of hector cores that are not based on ini files. These hector cores are going to have a mix of emissions and concentration driven inputs. Instead of having write code that sets up these specific hector cores at the beginning of each script we were thought it would be pretty handy to be able to set up a specific Hector code and save it as a .rda or R data file that could easily be imported. 🤔 Do we think that this capability would be possible / useful for other users?
Isn't that a neat idea! Huh. Yes.
Would there be some way to also write out metadata that contained the settings for that core?
( i’m wondering if it could get confusing, not knowing what was in each one.)
Yeah, I think metadata would definitely be part of this! I was actually envisioning an R object that combines a Hector core (which, AFAICT, is some kind of pointer?) with the actual data for its configuration. Any modifications you make to the object would apply to both the Hector core (through setvar) and to the attached metadata.
Pseudocode:
hector_object <- function(inifile, ...) {
list(
# Read the INI file into memory
config = read_ini(inifile),
# Launch a core with that config
core = hector::newcore(inifile, ...)
)
}
set_object_var <- function(obj, dates, variable, value) {
# Modify the config
obj$config[[variable]][dates] <- value
# Apply the same modification to the core
setvar(obj$core, dates, variable, value)
obj
}
Why is this an open issue for us? I mean, if someone wants this capability, they can just do what Alexey lays out above, basically
obj <- list(config = ..., core = hector::core(...))
saveRDS(obj)
right? But this seems outside of the scope of the hector package; by way of comparison, ggplot2 doesn't provide facilities for savings graph objects, but you can if you want to.
OK to close? @kdorheim
Closing this issue now that it is easier to point hector cores to ini files external to the hector package and Alexey's comment above outlines a solution for users that want to do this.