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
220 stars 71 forks source link

Set index functions should copy index attributes #305

Closed joshuaulrich closed 5 years ago

joshuaulrich commented 5 years ago

The index setting functions, index<-.xts() and .index<-.xts() should always copy the index attributes from x. As of 566ac0d119c012202c8d0f701897881c8f8ec5ea, .index<-.xts() errors (see #297), and index<-.xts() sets the attributes in a non-standard order.

x <- y <- .xts(1:3, 1:3, tzone = "UTC")
attributes(index(x))
# $tclass
# [1] "POSIXct" "POSIXt" 
#
# $tzone
# [1] "UTC"
#
# $class
# [1] "POSIXct" "POSIXt" 
index(y) <- .POSIXct(4:6, "UTC")
attributes(index(y))
# $tzone
# [1] "UTC"
#
# $tclass
# [1] "POSIXct" "POSIXt" 
#
# $class
# [1] "POSIXct" "POSIXt" 
.index(y) <- 4:6
attributes(index(y))
# Error in index.xts(y) : unsupported 'tclass' indexing type