Skip to content

window.xts start/end arguments do not support NA #345

Description

@harvey131

Description

The start and end arguments to window.xts do not support NA the same as if they were NULL.

Inside window_idx() the arguments are passed through .toPOSIXct() which will fail if they are logical (default) NA. However, the start/end arguments are later passed into the index_bsearch() function which does check if start/end are NA.

index_bsearch <- function(index., start, end)
{
  if(!is.null(start) && is.na(start)) return(NULL)
  if(!is.null(end) && is.na(end)) return(NULL)

Expected behavior

Treat start or end NA the same as if they were NULL.

Minimal, reproducible example

 x = xts::xts(1:10, as.POSIXct('2020-1-1') + 1:10)
window(x, start=as.POSIXct('2020-1-1'), end=NA)
# Error in .toPOSIXct(end, tzone(x)) : invalid time / time based class

Session Info

> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

loaded via a namespace (and not attached):
[1] zoo_1.8-7       compiler_3.6.2  xts_0.12-0      grid_3.6.2      lattice_0.20-38

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions