Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xts() contructor creates list coredata when 'x' is a zero-row data.frame #394

Closed
joshuaulrich opened this issue Mar 1, 2023 · 0 comments
Assignees
Labels
Milestone

Comments

@joshuaulrich
Copy link
Owner

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) 
@joshuaulrich joshuaulrich added this to the 0.13.1 milestone Mar 1, 2023
@joshuaulrich joshuaulrich self-assigned this Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant