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

if statement may use length > 1 logical #270

Closed
HughParsonage opened this issue Sep 26, 2018 · 0 comments
Closed

if statement may use length > 1 logical #270

HughParsonage opened this issue Sep 26, 2018 · 0 comments
Labels
Milestone

Comments

@HughParsonage
Copy link
Contributor

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
@joshuaulrich joshuaulrich added this to the 0.11-2 milestone Sep 30, 2018
joshuaulrich pushed a commit to HughParsonage/xts that referenced this issue Sep 30, 2018
Only the first element of class(order.by) is used in the if statement.
This will emit an error or warning when the environment variable
_R_CHECK_LENGTH_1_LOGIC2_ is true. We should make this explicit to
avoid the error or warning.

Fixes joshuaulrich#270.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants