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

names() doesnt show correct output for empty xts #223

Closed
VincentGuyader opened this issue Jan 20, 2018 · 3 comments
Closed

names() doesnt show correct output for empty xts #223

VincentGuyader opened this issue Jan 20, 2018 · 3 comments
Assignees
Labels

Comments

@VincentGuyader
Copy link

VincentGuyader commented Jan 20, 2018

Description

names of empty xts are NULL

Expected behavior

the names function should return the "correct" names even for an empty object

Minimal, reproducible example

``` r
library(xts)

data(sample_matrix)
sample.xts <- as.xts(sample_matrix, descr='my new xts object')
names(sample.xts["2007"]) # ok
#> [1] "Open"  "High"  "Low"   "Close"
sample.xts["0000"]# ok
#>      Open High Low Close
names(sample.xts["0000"]) # not OK
#> NULL

### Session Info

```r
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C                   LC_TIME=French_France.1252    

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

other attached packages:
[1] tidyxts_0.0.0.0009 xts_0.10-0         zoo_1.8-0          bindrcpp_0.2      

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.14       rstudioapi_0.7     whisker_0.3-2      bindr_0.1          xml2_1.1.1        
 [6] magrittr_1.5       roxygen2_6.0.1     usethis_1.1.0.9000 devtools_1.13.4    tidyselect_0.2.3  
[11] lattice_0.20-35    R6_2.2.2           rlang_0.1.6        stringr_1.2.0      dplyr_0.7.4       
[16] tools_3.4.2        grid_3.4.2         withr_2.1.1        timetk_0.1.0       commonmark_1.4    
[21] rprojroot_1.3-1    yaml_2.1.16        digest_0.6.13      assertthat_0.2.0   tibble_1.3.4      
[26] crayon_1.3.4       purrr_0.2.4.9000   clisymbols_1.2.0   testthat_2.0.0     memoise_1.1.0     
[31] glue_1.2.0         stringi_1.1.6      compiler_3.4.2     backports_1.1.2    lubridate_1.7.1   
[36] pkgconfig_2.0.1   
@joshuaulrich
Copy link
Owner

Thanks for the report. I can confirm this is a bug, since it's not consistent with zoo:

R> sample.zoo <- as.zoo(sample.xts)
R> names(sample.zoo["2007"]) # ok
[1] "Open"  "High"  "Low"   "Close"
R> sample.zoo["0000"]# ok
     Open High Low Close
R> names(sample.zoo["0000"]) # not OK
[1] "Open"  "High"  "Low"   "Close"

I'll investigate. Also, it would be great if you could test with the latest development versions of xts and zoo, to ensure the bug you're about to report isn't already fixed.

By the way, what is "tidyxts"?

@joshuaulrich joshuaulrich self-assigned this Jan 20, 2018
@VincentGuyader
Copy link
Author

Hi,
I like {dplyr} and I like {xts} so i'm trying to do this : https://github.com/ThinkR-open/tidyxts

Regards

@joshuaulrich
Copy link
Owner

After some investigation, it appears this behavior is caused by coredata.xts() returning an empty vector for zero-length xts objects. Whereas coredata.zoo() returns the original object, stripped of all its zoo-related attributes.

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