Skip to content
Prev 369707 / 398503 Next

Math ops behaviour with multiple classes

Thanks Bert, I think we agree on the current behaviour, but I'm still not sure if it's desirable.  The mode isn't used for method dispatch.  In the following example, I have to write `log.foo` in order for the correct method to be called.
+   floor(x) / 2
+ }
+   x %/% 2
+ }
[1] 0 0 0 0 0
attr(,"class")
[1] "integer" "foo"
[1] 0.0 0.0 0.5 0.5 0.5
+   res <- log(as.numeric(x))
+   class(res) <- c("numeric", "foo")
+   res
+ }
[1] 0.0 0.0 0.5 0.5 0.5
attr(,"class")
[1] "numeric" "foo"    

Not only would I have to write `log.foo`, but I'd need to add my own `foo` methods for the Math and Ops groups.  Using a different class system might be a better solution, but my preference would definitely be for the base functions to coerce the class to numeric (which it indeed does if there are not multiple classes).

Cole