setClass("foo", contains = "Date") setMethod("+", c("foo", "difftime"), function(e1, e2) callNextMethod())
This new class foo can then be used like a Date.
x <- new("foo", as.Date("2013-06-30")) > dt <- as.difftime(1, units = "days") > x + dt  "2013-07-01"
Using S4 has always struck me as being way too complicated. I could never remember the syntax, nor did I find it particularly enjoyable to write. On the other hand, with lambda.r, it is easy to extend a native type and make use of it.
Foo(x) %as% as.Date(x)
Usage of this type is also cleaner as the constructor is simpler.
> x <- Foo('2013-06-30') > dt <- as.difftime(1, units = "days") > x + dt  "2013-07-01"
This example demonstrates how lambda.r captures one aspect of literate programming by using a syntax that reads like simple exposition.