xts icon indicating copy to clipboard operation
xts copied to clipboard

[R-Forge #5250] [.xts fails when xts constructor is called on a ts object

Open joshuaulrich opened this issue 9 years ago • 1 comments

Submitted by: Joshua Ulrich Assigned to: Nobody R-Forge link

The error occurs in the _do_subset_xts C function.

mtsxts <- xts(ts(cbind(1:5,6:10)), Sys.Date()+1:5)
head(mtsxts)
# Error in `[.xts`(x, seq_len(n), , drop = FALSE) : 
#   invalid time series parameters specified

joshuaulrich avatar Feb 26 '15 01:02 joshuaulrich

The error actually occurs in the copyAttributes() C function. This is because it tries to copy the "tsp" attribute (c(1, 5, 1) in this case) to an object that doesn't have 5 rows.

This works, for example:

R$ mtsxts[1:5,]
           Series 1 Series 2
2022-06-02        1        6
2022-06-03        2        7
2022-06-04        3        8
2022-06-05        4        9
2022-06-06        5       10

We probably need to remove the tsp attribute when we subset by i (rows).

joshuaulrich avatar Jun 01 '22 19:06 joshuaulrich