Enable calling of C++ functions as methods of SnnsR-class
objects.
# S4 method for SnnsR
$(x, name)
object of class SnnsR-class
function to call
This function makes methods of SnnsR__ and SnnsCLib__ accessible via "$". If
no SnnsR__ method is present, then the according SnnsCLib__ method is
called. This enables a very flexible method handling. To mask a method from
SnnsCLib, e.g. to do some parameter checking or postprocessing, only a method
with the same name, but beginning with SnnsR__ has to be present in R. See
e.g. SnnsRObject$initializeNet
for such an implementation.
Error handling is also done within the method caller. If the result of a
function is a list with a member err
, then SnnsCLib__error
is
called to use the SNNS kernel function to get the corresponding error message
code and an R warning is thrown containing this message.
Furthermore, a serialization mechanism is implemented which all models present in the package use to be able to be saved and loaded by R's normal save/load mechanism (as RData files).
The completely trained object can be serialized with
s <- snnsObject$serializeNet("RSNNS_untitled")
snnsObject@variables$serialization <- s$serialization
For the models implemented, this is done in SnnsRObject$train
. If the S4 object is then saved and loaded,
the calling mechanism will notice on the next use of a function that the pointer to the C++ SnnsCLib object is nil
,
and if a serialization is present, the object is restored from this serialization before the method is called.