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

Converting xts with no dims to matrix throws error #294

Closed joshuaulrich closed 5 years ago

joshuaulrich commented 5 years ago

Attempts to convert an xts object to a matrix throws an error when the xts object does not have a dim attribute. This error occurred while doing reverse dependency checks for #245.

x <- .xts(1:3, 1:3)
x <- drop(x)       # drop dim attribute
m <- as.matrix(x)  # error
# Error in if (ncol(x) == 1) { : argument is of length zero

sessionInfo()
# R version 3.5.3 (2019-03-11)
# Platform: x86_64-pc-linux-gnu (64-bit)
# Running under: Ubuntu 18.04.2 LTS
#
# Matrix products: default
# BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
# LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
#
# locale:
#  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
# [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#
# attached base packages:
# [1] stats     graphics  grDevices utils     datasets  methods   base     
#
# loaded via a namespace (and not attached):
# [1] zoo_1.8-5       compiler_3.5.3  xts_0.11-2      grid_3.5.3     
# [5] lattice_0.20-38