Serialises a pigauto_fit object to disk, including the torch
model state. The saved file can be loaded on any machine with the
same pigauto version.
Details
Standard saveRDS() does not work for pigauto fits because
torch tensor states cannot be serialised by R's native mechanism.
This function converts the model state to a portable raw format
before saving.
Examples
# \donttest{
data(avonet300, tree300)
tree <- ape::keep.tip(tree300, tree300$tip.label[seq_len(30L)])
traits <- avonet300[match(tree$tip.label, avonet300$Species_Key),
c("Mass", "Wing.Length"), drop = FALSE]
rownames(traits) <- tree$tip.label
traits$Mass[seq_len(3L)] <- NA_real_
fit <- impute(traits, tree, epochs = 5L, verbose = FALSE)$fit
#> Error: Lantern is not loaded. Please use `install_torch()` to install additional dependencies.
path <- tempfile(fileext = ".pigauto")
save_pigauto(fit, path)
#> Error: object 'fit' not found
fit2 <- load_pigauto(path)
#> Error in load_pigauto(path): File not found: /tmp/RtmpZVwa03/file20f730be2c9e.pigauto
# }
