save_MAFs: Save or load MAF Python objects

View source: R/MAF.R

save_MAFsR Documentation

Save or load MAF Python objects

Description

Infusion fit results created using the mafR package contain (pointers to) Python objects, which are lost (their pointers being reduced to null pointers) when the fit object is saved on file and reloaded. The functions described here circumvent this issue.

save_MAFs will save the Python objects in distinct files. load_MAFs will load them back into the fit object, not overriding anyone pre-existing into the target fit object. The Python objects are saved under, and read from, files whose names are made of "jointdens", "pardens"... and the given prefix and extension.

Usage

save_MAFs(object, ext="_MAF.pkl", prefix="")
load_MAFs(object, ext="_MAF.pkl", prefix="", set_path_only=FALSE)

Arguments

object

An object of class "SLik_j" as produced by the up-to-date Infusion workflow.

prefix, ext

Character: Prefix and extension for the filename of each saved MAF object.

set_path_only

Boolean: if TRUE, checks the presence of the saved MAF files, but do not load them, and (re)set the path information in the object (see Details for a programming context of usage).

Details

Both functions can write file path information into the input object's load_MAFs_info element (an environment), where it can be read afterwards. save_MAFs will do so in all cases, and load_MAFs will do so when called with argument set_path_only=TRUE. When a bootstrap is run using parallelisation, the child processes can thus load files using their location information stored in this way. When the files have been moved after the save_MAFs call, their location information must then be updated using load_MAFs(., set_path_onlTRUE).

Value

Both functions return the updated input object.

See Also

reticulate::py_save_object is used to save the Python objects.

Examples

## Given object 'slik_j' of class SLik_j
# save_MAFs(slik_j, prefix = "2024Feb30_")
## => '2024Feb30_jointdens_MAF.pkl', etc.
# save(slik_j, file="slik_j.rda") 
## => Objects from Python environments are not saved in the RData file. 

# and later:
# load(file="slik_j.rda") 
# slik_j <- load_MAFs(slik_j, prefix = "2024Feb30_")
## Objects from pkl files are put back at the right place in 'slik_j'. 


Infusion documentation built on Sept. 30, 2024, 9:16 a.m.

Related to save_MAFs in Infusion...