The generation methods seem to be broken when the minimum value of each element is one. Let’s fix this.
n <- 5
generate_matrix_hetero(row_sum = rep(5, 5), mat_min = array(1, dim = c(n, n)))
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 1 1 1 1
## [2,] 1 1 1 1 1
## [3,] 1 1 1 1 1
## [4,] 1 1 1 1 1
## [5,] 1 1 1 1 1
The default value of any argument is evaluated lazily. It was occuring at the end of the function. I incorrectly assumed that it would occur at the start.
## R version 3.4.3 (2017-11-30)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04.3 LTS
##
## Matrix products: default
## BLAS: /usr/lib/openblas-base/libblas.so.3
## LAPACK: /usr/lib/libopenblasp-r0.2.18.so
##
## locale:
## [1] LC_CTYPE=fr_FR.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=fr_FR.UTF-8 LC_COLLATE=fr_FR.UTF-8
## [5] LC_MONETARY=fr_FR.UTF-8 LC_MESSAGES=fr_FR.UTF-8
## [7] LC_PAPER=fr_FR.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggplot2_2.2.1 dplyr_0.7.4 tidyr_0.2.0 purrr_0.2.0 stringr_1.2.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.10 knitr_1.15.1 bindr_0.1 magrittr_1.5
## [5] munsell_0.4 colorspace_1.2-2 R6_2.1.0 rlang_0.1.6
## [9] plyr_1.8.1 tools_3.4.3 grid_3.4.3 gtable_0.1.2
## [13] pacman_0.4.6 htmltools_0.3.6 lazyeval_0.2.0 yaml_2.1.13
## [17] rprojroot_1.2 digest_0.6.3 assertthat_0.1 tibble_1.3.1
## [21] bindrcpp_0.2 glue_1.2.0 evaluate_0.10 rmarkdown_1.8
## [25] stringi_0.5-5 compiler_3.4.3 scales_0.4.1 backports_1.0.5
## [29] pkgconfig_2.0.1