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

`suffixes` not respected in `xts::merge` when `colnames` of merging objects are the same #369

Closed bollard closed 2 years ago

bollard commented 2 years ago

Description

suffixes are not applied when column names of the merging objects are already the same

Expected behavior

suffixes would be applied as specified

Minimal, reproducible example

idx <- Sys.Date() - 1:10
x1 <- xts(1:10, order.by = idx, dimnames = list(NULL, 'foo'))
x2 <- xts(2:11, order.by = idx, dimnames = list(NULL, 'foo'))
colnames(cbind(x1, x2, suffixes = c('x1', 'x2')))
> [1] "foo"   "foo.1"

In this example, I'd expect to see c("foo.x1", "foo.x2")

Session Info

[Insert your sessionInfo() output]

R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

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

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

other attached packages:
 [1] quadprog_1.5-8    lubridate_1.7.10  RMariaDB_1.1.1    xts_0.12.1        zoo_1.8-9         BDRex_4.0.16     
 [7] svUnit_1.0.3      rJava_0.9-13      data.table_1.14.0 bdr_0.1.0.9000    renv_0.15.5      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6      magrittr_2.0.1  hms_1.0.0       bit_4.0.4       lattice_0.20-44 rlang_1.0.2     fansi_1.0.3    
 [8] tools_3.6.3     grid_3.6.3      utf8_1.2.2      cli_3.3.0       DBI_1.1.1       ellipsis_0.3.2  bit64_4.0.5    
[15] tibble_3.1.7    lifecycle_1.0.0 crayon_1.5.1    vctrs_0.4.1     glue_1.6.2      pillar_1.7.0    compiler_3.6.3 
[22] generics_0.1.0  pkgconfig_2.0.3
joshuaulrich commented 2 years ago

You're using version 0.12.1 and this has been fixed in #38 which has been merged to master.

R$ idx <- Sys.Date() - 1:10
   x1 <- xts(1:10, order.by = idx, dimnames = list(NULL, 'foo'))
   x2 <- xts(2:11, order.by = idx, dimnames = list(NULL, 'foo'))
   colnames(cbind(x1, x2, suffixes = c('x1', 'x2')))
[1] "foo.x1" "foo.x2"
R$ packageVersion("xts")
[1] '0.12.1.2'
bollard commented 2 years ago

Doh! Yes, my apologies. Sorry for the spam. Any idea when we can expect a new CRAN release? 0.12.1 was released in September 2020. Would be great if we could get out all the latest fixes. Thanks