xts objects should always have (atomic) vector/matrix coredata. List coredata is not supported, but the xts() constructor allows you to create an object with list coredata when the input is a zero-row data.frame. The constructor should instead call as.matrix() on the data.frame.
library(xts)
zero_row_df <- data.frame(date = .Date(numeric(0)), x = numeric(0), y = numeric(0))
zero_row_xts <- xts(zero_row_df[, -1], zero_row_df[, 1])
str(zero_row_xts)
## An empty xts object
## Data: list [2, 0] # <- list!
## Index: Date [0] (TZ: "UTC")
## xts Attributes:
## $ row.names: int(0)
xts objects should always have (atomic) vector/matrix coredata. List coredata is not supported, but the
xts()
constructor allows you to create an object with list coredata when the input is a zero-row data.frame. The constructor should instead callas.matrix()
on the data.frame.