[R] Zero Index Origin?
ggrothendieck at myway.com
Thu Apr 1 08:51:59 CEST 2004
Bob Cain <arcane <at> arcanemethods.com> writes:
> A question I have from my very limited
> understanding yet of OO is whether such objects could be
> passed to legacy functions with any expectation of correct
Typically you need to write a wrapper but sometimes you get it for
free. For example, in the vector0 class that I displayed previously,
note that no multiplication method was defined for it yet the
example included multiplication and it worked.
Oarray would get the same benefit.
Note that if a routine f.legacy(x) does not make use of indices at all then
f(unclass(v)) where v is of class vector0 or Oarray would be sufficient
(untested). Also you can define a generic that dispatches to the
f <- function(x) UseMethod("f") # defines a generic
f.Orray <- function(x) f(unclass(x))
f.default <- f.legacy
Now you can call f(x) and if x is a legacy variable f.legacy gets
used and if x is Oarray then f.Oarray gets used.
More information about the R-help