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

Restore behaviour from 0.10-2 to .xts() #250

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/xts.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ function(x=NULL, index, tclass=c("POSIXct","POSIXt"),
.indexFORMAT <- eval(dots.names$.indexFORMAT,parent.frame())
else
.indexFORMAT <- NULL

## restore behaviour from v0.10-2
tclass <- .indexCLASS
xx <- .Call("add_xtsCoreAttributes", x, index, .indexCLASS, tzone, tclass,
c('xts','zoo'), .indexFORMAT, PACKAGE='xts')
# remove .indexFORMAT and .indexTZ that come through Ops.xts
Expand Down
45 changes: 45 additions & 0 deletions inst/unitTests/runit.xts.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,48 @@ test..xts_dimnames_in_dots <- function() {
y <- xts(1:5, index(x), dimnames = list(NULL, "x"))
checkEquals(x, y)
}

checkXtsClass <- function(xts, class) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks for attributes on specific objects, but it probably should use the extractor functions indexClass() and tclass().

checkEquals(tclass(xts), class)
checkEquals(indexClass(xts), class)
checkEquals(attr(attr(xts, "index"), "tclass"), class)
}

### Check that .indexCLASS takes precedence over tclass when both specified
test..xts_class <- function() {
checkXtsClass(.xts(1, 1), c("POSIXct", "POSIXt"))
checkXtsClass(.xts(1, 1, tclass="timeDate"), "timeDate")
checkXtsClass(.xts(1, 1, .indexCLASS="Date"), "Date")
checkXtsClass(.xts(1, 1, tclass="timeDate", .indexCLASS="Date"), "Date")

## also check that tclass is ignored if specified as part of index
checkXtsClass(.xts(1, structure(1, tzone="",tclass="yearmon")), c("POSIXct", "POSIXt"))
checkXtsClass(.xts(1, structure(1, tzone="",tclass="yearmon"), tclass="timeDate"), "timeDate")
checkXtsClass(.xts(1, structure(1, tzone="",tclass="yearmon"), .indexCLASS="Date"), "Date")
checkXtsClass(.xts(1, structure(1, tzone="",tclass="yearmon"), tclass="timeDate", .indexCLASS="Date"), "Date")
}

checkXtsTz <- function(xts, tzone) {
checkEquals(tzone(xts), tzone)
checkEquals(indexTZ(xts), tzone)
checkEquals(attr(attr(xts, "index"), "tzone"), tzone)
}

.setUp <- function() {
Sys.setenv(TZ="UTC")
}

### Check that tzone is honoured and .indexTZ ignored
test..xts_tzone <- function() {
checkXtsTz(.xts(1, 1), "UTC")
checkXtsTz(.xts(1, 1, tzone="Europe/London"), "Europe/London")
## this case passes in 0.10-2 but looks wrong
checkXtsTz(.xts(1, 1, .indexTZ="America/New_York"), "UTC")
checkXtsTz(.xts(1, 1, tzone="Europe/London", .indexTZ="America/New_York"), "Europe/London")

## Cases where tzone is specified in the index
checkXtsTz(.xts(1, structure(1, tzone="Asia/Tokyo",tclass="yearmon")), "Asia/Tokyo")
checkXtsTz(.xts(1, structure(1, tzone="Asia/Tokyo",tclass="yearmon"), tzone="Europe/London"), "Europe/London")
checkXtsTz(.xts(1, structure(1, tzone="Asia/Tokyo",tclass="yearmon"), .indexTZ="America/New_York"), "Asia/Tokyo")
checkXtsTz(.xts(1, structure(1, tzone="Asia/Tokyo",tclass="yearmon"), tzone="Europe/London", .indexTZ="America/New_York"), "Europe/London")
}