Skip to content

Commit

Permalink
Do not warn when .xts ctor ignores tclass
Browse files Browse the repository at this point in the history
The current behavior ignores the tclass attribute on the index passed
to .xts(). This is a bug, but throwing a warning breaks existing
packages and causes errors in their CRAN checks. Reinstate the warning
after fixing dependencies.

See #245.
  • Loading branch information
joshuaulrich committed Jan 14, 2020
1 parent 45ff1ad commit 96b4798
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions R/xts.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,14 @@ function(x=NULL, index, tclass=c("POSIXct","POSIXt"),
# tclass argument will override the index attribute, but it shouldn't...
index.class <- attr(index, 'tclass')
default.class <- c("POSIXct", "POSIXt")
if(!is.null(index.class) && !all(index.class %in% default.class)) {
warning("the index tclass attribute is ", index.class,
" but will be changed to (POSIXct, POSIXt)")
}
### FIXME:
### This warning causes errors in dependencies (e.g. portfolioBacktest,
### when the warning is thrown from PerformanceAnalytics). Reinstate this
### warning after fixing downstream packages.
### if(!is.null(index.class) && !all(index.class %in% default.class)) {
### warning("the index tclass attribute is ", index.class,
### " but will be changed to (POSIXct, POSIXt)")
### }
}

if(hasArg(".indexTZ")) {
Expand Down
1 change: 1 addition & 0 deletions inst/unitTests/runit.xts.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ test..xts_dimnames_in_dots <- function() {
}

test..xts_ctor_warns_if_index_tclass_not_NULL_or_POSIXct <- function() {
DEACTIVATED("Warning causes errors in dependencies")
op <- options(warn = 2)
on.exit(options(warn = op$warn))

Expand Down

0 comments on commit 96b4798

Please sign in to comment.