Several permutations of calling binary operators on xts and matrix arguments results in a malformed xts object. If the xts object does not have a dim attribute, the result has a c("xts", "zoo") class, but no index attribute. The xts result will also have rownames if the matrix does.
data(sample_matrix)
x <- as.xts(sample_matrix[1:5, c(1,4)])
d <- coredata(x)
m <- as.matrix(x)
xv <- drop(x[,1])
# all these are okay: index, class, dim, dimnames (no rownames)
attributes(x-d)
attributes(x-m)
attributes(x-d[,1])
attributes(x-m[,1])
# these are various degrees of wrong
attributes(xv-d) # no index
attributes(xv-m) # no index, has rownames
attributes(xv-d[,1]) # okay
attributes(xv-m[,1]) # has names
# not clear what is the correct behavior here
# these pick up the dim attribute from the 1-column matrix
attributes(xv-d[, 1, drop = FALSE])
attributes(xv-m[, 1, drop = FALSE]) # has rownames
Session Info
These were found as part of testing #245.
For reference, the behavior of the last 2 results is consistent with the current version (0.11-2):
Several permutations of calling binary operators on xts and matrix arguments results in a malformed xts object. If the xts object does not have a dim attribute, the result has a
c("xts", "zoo")
class, but noindex
attribute. The xts result will also have rownames if the matrix does.Session Info
These were found as part of testing #245.
For reference, the behavior of the last 2 results is consistent with the current version (0.11-2):