[R] inconsistency between timeSeries and zoo causing a problem with rbind

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Sun Nov 16 17:03:28 CET 2008


On Sun, 16 Nov 2008, Tolga Uzuner wrote:

> I believe there is a recently introduced inconsistency between timeSeries and 
> zoo which is causing a problem with rbind. I had previously reported that I 
> was having problems with rbind in the following code:
>
> library(zoo)
> foo<-zoo(1,order.by=as.Date("2007-10-09"))
> bar<-zoo(2,order.by=as.Date("2007-10-10"))
> bar <- rbind(zoo(0, order.by = index(foo)[1]), bar)
> bar

What happens is the following:
   - There is base:::rbind() and methods:::rbind(). The former is just
     an .Internal() call while the latter additionally does consistency
     checks. The consistency checks require that you can only rbind()
     if the result has a dimension.
   - base:::rbind() is usually found first, even if "methods" is loaded.
     But if you load "timeSeries" this changes and methods:::rbind() is
     found first. I haven't figured out why this happens but it does _not_
     for other S4 packages (such as "Matrix" for example).
   - Thus, if you rbind 1d zoo series, the result is also 1d and has no
     dimension. If "timeSeries" is loaded, methods:::rbind() is called
     which assumes a dimension and fails if there is none.

What should be done:
   - I'm not sure whether "timeSeries" can be changed so that
     base:::rbind() is still found first.
   - Maybe methods:::rbind() could be made more liberal so that it does
     not fail for 1d return values. Of course, one could argue that a row
     bind only makes sense if there are rows and columns. But, then again,
     maybe it is possible to allow other usages as well.
   - You can work around this as a user of zoo series, by calling c()
     instead of rbind() for 1d series, i.e.,
       c(foo, bar)
     always works with or without "timeSeries" attached. Moreover, c()
     even works for 2d zoo series.

hth,
Z



More information about the R-help mailing list