Generic to save assorted R objects into appropriate on-disk representations. More methods may be defined by other packages to extend the alabaster.base framework to new classes.
saveObject(x, path, ...)
dir
is created and populated with files containing the contents of x
.
NULL
should be invisibly returned.
Application developers can override saveObject
by specifying a custom function in altSaveObject
.
This can be used to point to a different function to handle the saving process for each class.
The custom function can be as simple as a wrapper around saveObject
with some additional actions (e.g., to save more metadata),
or may be as complex as a full-fledged generic with its own methods for class-specific customizations.
Comments for extension developers
Methods for the
saveObject
generic should create a directory atpath
in which the contents ofx
are to be saved. The files may consist of any format, though language-agnostic formats like HDF5, CSV, JSON are preferred. For more complex objects, multiple files and subdirectories may be created withinpath
. The only strict requirements are:There must be an
OBJECT
file insidepath
, containing a JSON object with a"type"
string property that specifies the class of the object, e.g.,"data_frame"
,"summarized_experiment"
. This will be used by loading functions to determine how to load the files into memory.The names of files and subdirectories should not start with
_
or.
. These are reserved for applications, e.g., to build manifests or to store additional metadata.Callers can pass optional parameters to specific
saveObject
methods via...
. Any options recognized by a method should be prefixed by the name of the class used in the method's signature, e.g., any options forsaveObject,DataFrame-method
should start withDataFrame.
. This scoping avoids conflicts between otherwise identically-named options of different methods.When developing
saveObject
methods of complex objects, a simple approach is to decomposex
into its “child” components. Each component can then be saved into a subdirectory ofpath
, levering the existingsaveObject
methods for the component classes. In such cases, extension developers should actually callaltSaveObject
on each child component, rather than calling saveObject directly. This ensures that any application-level overrides of the loading functions are respected. It is expected that each method will forward...
(possibly after modification) to any internalaltSaveObject
calls.