[Rd] Constructor/extractor.

Hervé Pagès hpages at fhcrc.org
Thu Mar 6 00:18:45 CET 2014

Hi Rolf, Barry,

On 03/04/2014 08:08 AM, Barry Rowlingson wrote:
> On Tue, Mar 4, 2014 at 1:47 AM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
>> Questions:
>> ==========
>> (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.
>   I don't see why you can't conceptually think of w = owin(some_ppp_object)
> as an owin "Constructor" rather than an "Accessor". Its "constructing" (and
> returning) an owin from an object, it just happens to be as simple as
> getting a component from that object.
>   The raster package has the 'extent' function - you can create an extent
> with extent(xmin,xmax,,,etc), get the extent of a raster with extent(r), or
> set the extent of a raster with extent(r1) <- extent(r2), so I don't see
> any problem with:
> w1 = owin(poly=...) # construct polygon owin
> ppp1 = ppp(x,y,window=w1)
> ppp2 = ppp(x,y, window=owin(ppp1)) # construct window from ppp object
> owin(ppp1) = owin(ppp2)  # give ppp1 the owin of ppp2
> That all reads pretty nicely. As long as owin(...) returns an observation
> window and owin<-(...) assigns an observation window to an object that can
> validly have one, I don't think you can go wrong. I've probably already
> tried to do "owin(ppp1)=..." a few times...

I agree with Barry. Once you realize there is no clear line between
constructor and extractor (conceptually every function can actually
be thought of as a constructor), then re-using the same function name
(via methods of a generic function) doesn't sound too bad. An example
of this design is the strand() generic in Bioconductor: can be used
to get or set the strand factor of an object containing such a
component (e.g. a GRanges object), and also for constructing a
strand factor from different kinds of input (character, logical,
integer vector, etc...)


> Barry
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319

More information about the R-devel mailing list