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

if statement may use length > 1 logical #270

Closed HughParsonage closed 6 years ago

HughParsonage commented 6 years ago

Description

if statement in R/xts.R may use length > 1 objects and so may cause an warning/error if the _R_CHECK_LENGTH_1_LOGIC2_ is set or at the very least silently ignore other elements of class(order.by).

Expected behavior

No warning or error

Minimal, reproducible example

library(xts)
library(data.table)
  Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = TRUE)
  dt = data.table(index = as.POSIXct((as.Date("2014-12-12")-49):as.Date("2014-12-12"),
                                     origin="1970-01-01"),
                  quantity = as.numeric(rep(c(1:5),10)),
                  value = rep(c(1:10)*100,5))
xt = as.xts(matrix(data = c(dt$quantity, dt$value),
                   ncol = 2,
                   dimnames = list(NULL,c("quantity","value"))),
            order.by = dt$index)
#> Error in orderBy == "timeDate" && missing(tzone): 'length(x) = 2 > 1' in coercion to 'logical(1)'

Session Info

R Under development (unstable) (2018-09-23 r75355)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] xts_0.11-1        zoo_1.8-4         data.table_1.11.6

loaded via a namespace (and not attached):
[1] compiler_3.6.0  grid_3.6.0      lattice_0.20-35