bluefoxr / COINr

COINr
https://bluefoxr.github.io/COINr/
Other
25 stars 8 forks source link

Error: attempt to select less than one element in integerOneIndex #52

Closed carranzajuanp closed 1 year ago

carranzajuanp commented 1 year ago

Replicate:

x1 = c(1:100)
x1 = replicate(250, sample(x1, size = 1))
x2 = c(500:555)
x2 = replicate(250, sample(x2, size = 1))
x3 = c(250:750)
x3 = replicate(250, sample(x3, size = 1))
x4 = c(1:90)
x4 = replicate(250, sample(x4, size = 1))
uCode <- do.call(paste0, replicate(3, sample(LETTERS, 250, TRUE), FALSE))
iData = data.frame(cbind(uCode, x1, x2, x3, x4))
iData$uCode = as.character(iData$uCode)
iData$x1 = as.numeric(iData$x1)
iData$x2 = as.numeric(iData$x2)
iData$x3 = as.numeric(iData$x3)
iData$x4 = as.numeric(iData$x4)
iData = iData[!duplicated(iData$uCode),]
iCode = names(iData[,2:ncol(iData)])
Level = c(1, 1, 1, 1)
Direction = c(1, 1, 1, 1)
Weight = c(1, 1, 1, 1)
Parent = c(NA, NA, NA, NA)
Type = c("Indicator","Indicator","Indicator","Indicator")
iMeta = data.frame(cbind(iCode,
                         Level,
                         Direction,
                         Weight,
                         Parent,
                         Type))
iMeta$Level = as.numeric(Level)
iMeta$Direction = as.numeric(Direction)
iMeta$Weight = as.numeric(Weight)
check_iData(iData)
check_iMeta(iMeta)
iMeta = iMeta[,c("Level","iCode","Direction","Weight","Parent","Type")]
head(iMeta, 5)
coin <- new_coin(iData = iData,
                 iMeta = iMeta)

This returns the following error:

iData checked and OK.
iMeta checked and OK.
Error in .subset2(x, i, exact = exact) : 
  attempt to select less than one element in integerOneIndex

Session:

R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=es_AR.UTF-8       LC_NUMERIC=C               LC_TIME=es_AR.UTF-8        LC_COLLATE=es_AR.UTF-8     LC_MONETARY=es_AR.UTF-8   
 [6] LC_MESSAGES=es_AR.UTF-8    LC_PAPER=es_AR.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=es_AR.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] COINr_1.1.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10      rstudioapi_0.13  magrittr_2.0.3   tidyselect_1.2.0 munsell_0.5.0    colorspace_2.0-3 R6_2.5.1         rlang_1.0.6     
 [9] fansi_1.0.3      dplyr_1.1.0      tools_4.2.1      grid_4.2.1       gtable_0.3.0     utf8_1.2.2       cli_3.6.0        ellipsis_0.3.2  
[17] readxl_1.4.0     tibble_3.1.7     lifecycle_1.0.3  crayon_1.5.2     zip_2.2.0        ggplot2_3.3.6    vctrs_0.5.2      glue_1.6.2      
[25] openxlsx_4.2.5   stringi_1.7.6    cellranger_1.1.0 compiler_4.2.1   pillar_1.7.0     generics_0.1.3   scales_1.2.0     pkgconfig_2.0.3 
bluefoxr commented 1 year ago

You only defined one level in iMeta, this is not normally expected in a composite indicator because you have not defined any aggregate levels, therefore you won't be able to aggregate. However, I have made a change so you can at least assemble the coin in this scenario, and now there is a warning message. As noted in the warning, you will likely encounter problems with some COINr functions as a result. Try installing the latest version and see what happens.

carranzajuanp commented 1 year ago

Thanks Will!