[Rd] Constructor/extractor.

Rolf Turner r.turner at auckland.ac.nz
Tue Mar 4 02:47:18 CET 2014


Preamble:
=========

In spatial point pattern analysis an important component of a point 
pattern object is the *observation window*.  In the spatstat package we 
have the function owin() to *construct* such a window.  It creates an 
object of class "owin" which can happily exist separately from any point 
pattern object (object of class "ppp").

However we have at the moment no convenient function to *extract* the 
observation component of a ppp object, nor have we a really convenient 
means of (re-) assigning the window component of such an object.  We can
extract the component via X$window or more suavely via as.owin(X) --- 
but the latter is rather counter-intuitive and lacks parallelism with 
other usage.  Re-assignment of the observation window component of X can
be done either via X$window <- W or X <- X[W].  These are not quite the 
same.  The former may leaves points which are outside of W hanging 
around. The latter does not suffer from this defect, and is more suave, 
but is not as intuitive as it might be.

I suggested that we could make the owin() function generic, make the 
current owin() creator function into owin.default(), and build an 
extractor function owin.ppp() (and an assignment function owin<-.ppp () 
to assign an observation window to a ppp object).

It was pointed out to me that this would make for an unorthodox syntax 
It is at the very least *unusual* if not unheard of for a function to be 
used both for *creation* of objects and for *extraction* of components 
from other objects.

Questions:
==========

My questions to R-devel are:

(1) Are there any other functions in R that serve this dual role of
constructor and extractor?

(2) Even if there are no such functions, is there anything intrinsically 
*wrong* with having a function possessing this somewhat schizophrenic 
nature?  Is it likely to cause confusion, induce syntactical mistakes, 
create errors, or produce wrong results?

Any thoughts, comments, insights or suggestions gratefully received.

cheers,

Rolf Turner



More information about the R-devel mailing list