joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
219 stars 71 forks source link

Creating and subsetting empty xts objects removes dim attr #402

Open joshuaulrich opened 1 year ago

joshuaulrich commented 1 year ago

xts objects should almost always have a dim attribute, but these xts objects do not have dims.

I say "almost always" because merge.xts() has removed the 'dim' attribute from zero-column results since the beginning of time. It will very likely break stuff if we set dim(result) <- c(0, 0) because users probably use is.null(dim(x))... xts even does this internally.

x <- xts(numeric(0), .Date(integer(0)))
dim(x)
## NULL
dim(x[0,])
## NULL
dim(x[Sys.Date(),])
## NULL

Strangely, the .xts() constructor adds dims to an empty object and says it has 1 column. I expected it to be c(0, 0) instead.

x. <- .xts(numeric(0), .POSIXct(numeric(0)))
dim(x.)
## [1] 0 1

This is a regression from version 0.12.2.