is.active {RNetica} | R Documentation |
NeticaSession
, NeticaBN
,
NeticaNode
, CaseStream
, and
NeticaRNG
objects all contain embedded pointers
into Netica's memory. The function
is.active()
checks to see that the corresponding Netica object
still exists.
is.active(x)
x |
A |
Internally, NeticaSession
,
NeticaBN
and
NeticaNode
objects all contain pointers to the
corresponding Netica objects. The DeleteNetwork()
and
DeleteNodes()
functions deletes the Netica objects (and
clears the pointers in the R objects). It is difficult to control
when R objects are deleted, especially if they are protected in data
structures that are saved in the workspace. The function
is.active()
is meant to check if the corresponding object is
still valid. In most cases, RNetica will give an error (or at least a
warning) if an inactive object is supplied as an argument.
For CaseStream
objects (and its sub-classes
FileCaseStream
and
MemoryCaseStream
) active and open have the same
meaning.
For NeticaRNG
objects, they become inactive when
they are freed.
Note that the function StopNetica()
should make all
NeticaBN
and NeticaNode
objects inactive. Thus, these
objects cannot be saved from one R session to another, and should be
recreated when needed. In particular, any Netica object restored from
a saved workspace should be inactive.
The function is.active()
returns TRUE
if the argument
still points to a network or node loaded in Netica's memory, and
FALSE
if that network or node has been deleted. It returns
NA
if the argument is not a NeticaSession
,
NeticaBN
, NeticaNode
, CaseStream
, or
NeticaRNG
object.
If x
is a list, then a logical vector of the same length of
x
is returned with is.active()
recursively applied to
each one.
The actual test done is to test the pointer to see if it is null or not. It should be the case that when an R object is disconnected from its Netica counterpart, the pointer is set to null.
Russell Almond
http://norsys.com/onLineAPIManual/index.html, http://lib.stat.cmu.edu/R/CRAN/doc/manuals/R-exts.html
StopNetica()
, NeticaBN
,
DeleteNetwork()
, NeticaNode
,
DeleteNodes()
, NeticaSession
,
CaseStream
, NeticaRNG
sess <- NeticaSession() stopifnot(!is.active(sess)) startSession(sess) stopifnot(is.active(sess)) anet <- CreateNetwork("ActiveNet", session=sess) stopifnot(is.active(anet)) anodes <- NewContinuousNode(anet,paste("ActiveNode",1:2,sep="")) stopifnot(all(is.active(anodes))) inode <- DeleteNodes(anodes[[1]]) stopifnot(!is.active(anodes[[1]])) stopifnot(!is.active(inode)) stopifnot(is.active(anodes[[2]])) DeleteNetwork(anet) stopifnot(!is.active(anet)) ## Node gets deleted along with network stopifnot(!any(is.active(anodes))) rng <- NewNeticaRNG(1, session=sess) stopifnot(is.active(rng)) FreeNeticaRNG(rng) stopifnot(!is.active(rng)) casefile <- tempfile("testcase",fileext=".cas") filestream <- CaseFileStream(casefile, session=sess) stopifnot(is.active(filestream)) CloseCaseStream(filestream) stopifnot(!is.active(filestream)) stopSession(sess) stopifnot(!is.active(sess))