andrewcparnell / simmr

A stable isotope mixing model in R
https://andrewcparnell.github.io/simmr/
28 stars 8 forks source link

Combine_sources error #15

Closed VirginiaMorera closed 5 years ago

VirginiaMorera commented 5 years ago

Hello,

I'm getting an error when combining sources with combine_sources( ):

Error` in `[<-`(`*tmp*`, to_combine_cols[1], , value = apply(old_source_means[to_combine_cols,  : 
  subscript out of bounds"

My data is composed of two groups, 2 isotopes, 4 sources, and I want to combine sources 3 and 4.

I went digging a bit into the function, and I think I've spotted the problem, and it works for me after the change, but I don't dare to commit it as maybe I've missed something. Here's the deal:

In

# 1 combine the chosen source means
old_source_means = simmr_out$input$source_means
simmr_new_out$input$source_means = old_source_means[-to_combine_cols[2], ,
                                                               drop = FALSE]
simmr_new_out$input$source_means[to_combine_cols[1], ] = apply(old_source_means[to_combine_cols, ,drop = FALSE], 2, 'mean')

I've changed the [1] in the last line by a [2], so I've got

# 1 combine the chosen source means
old_source_means = simmr_out$input$source_means
simmr_new_out$input$source_means = old_source_means[-to_combine_cols[2], ,
                                                  drop = FALSE]
simmr_new_out$input$source_means[to_combine_cols[2], ] = apply(old_source_means[to_combine_cols, ,drop = FALSE], 2, 'mean')

If this is done in steps 1 through 5, the results seem to me to be what I expected, and the function doesn't crash.

I've tried this with other datasets and other computers with different R versions, and have got the same error, so I guess the error is not in the data or the session. Just in case, below is my session info, and I can send the data over if anyone wants to test it.


R version 3.5.0 (2018-04-23) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

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

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

other attached packages: [1] simmr_0.3 ggplot2_3.0.0 rjags_4-6 coda_0.19-2

loaded via a namespace (and not attached):
[1] Rcpp_0.12.19 pillar_1.2.2 compiler_3.5.0
[4] DEoptimR_1.0-8 plyr_1.8.4 bindr_0.1.1
[7] viridis_0.5.1 compositions_1.40-2 tools_3.5.0
[10] digest_0.6.15 boot_1.3-20 viridisLite_0.3.0
[13] tibble_1.4.2 gtable_0.2.0 lattice_0.20-35
[16] pkgconfig_2.0.1 rlang_0.2.0 yaml_2.1.19
[19] bindrcpp_0.2.2 gridExtra_2.3 withr_2.1.2
[22] dplyr_0.7.6 stringr_1.3.0 grid_3.5.0
[25] tidyselect_0.2.4 glue_1.2.0 robustbase_0.93-2
[28] R6_2.2.2 bayesm_3.1-0.1 tensorA_0.36.1
[31] purrr_0.2.4 reshape2_1.4.3 magrittr_1.5
[34] scales_0.5.0 MASS_7.3-49 assertthat_0.2.0
[37] colorspace_1.3-2 labeling_0.3 stringi_1.1.7
[40] energy_1.7-5 lazyeval_0.2.1 munsell_0.4.3

--

andrewcparnell commented 5 years ago

Hi VirginiaMorera,

Apologies for not replying sooner to this. For some reason this issue didn't appear in my list of open issues. I will test this and make changes if correct.

Andrew

andrewcparnell commented 5 years ago

Just created a new version on GitHub (and submitted to CRAN) - v0.4.1. Hopefully it fixes your issue. If not please re-open this thread.