grunwaldlab / poppr

🌶 An R package for genetic analysis of populations with mixed (clonal/sexual) reproduction
https://grunwaldlab.github.io/poppr
68 stars 26 forks source link

R 3.6.0 changes default randomization scheme. #197

Closed zkamvar closed 5 years ago

zkamvar commented 5 years ago

A bias in the default sample() was fixed (https://twitter.com/kjhealy/status/1100202130466656256), but this now means that all tests that rely on random sampling are vulnerable to failure.

A perfect example is here:

checking tests ... [11s/15s] ERROR
  Running ‘test-all.R’ [11s/15s]
Running the tests in ‘tests/test-all.R’ failed.
Complete output:
  > library(testthat)
  > options(poppr.debug = TRUE)
  > test_check("poppr")
  Loading required package: poppr
  Loading required package: adegenet
  Loading required package: ade4

     /// adegenet 2.1.1 is loaded ////////////

     > overview: '?adegenet'
     > tutorials/doc/questions: 'adegenetWeb()'
     > bug reports/feature requests: adegenetIssues()

  This is poppr version 2.8.1. To get started, type package?poppr
  OMP parallel support: available
  ── 1. Failure: rrmlg produces the correct mlgs (@test-round-robin.R#24) ───────
  `rrx_m` not equivalent to `mlg_truth`.
  11/15 mismatches (average diff: 1.73)
  [2] 3 - 2 == 1
  [3] 2 - 3 == -1
  [5] 4 - 1 == 3
  [6] 1 - 2 == -1
  [7] 3 - 4 == -1
  [9] 1 - 3 == -2
  [10] 4 - 1 == 3
  [12] 4 - 3 == 1
  [13] 3 - 2 == 1
  ...

  ══ testthat results ═══════════════════════════════════════════════════════════
  OK: 308 SKIPPED: 186 FAILED: 1
  1. Failure: rrmlg produces the correct mlgs (@test-round-robin.R#24)

  Error: testthat unit tests failed
  Execution halted

Luckily, THIS particular test can be fixed by explicitly defining the matrix as opposed to sampling it.

zkamvar commented 5 years ago
set.seed(69)
x <- matrix(sample(LETTERS[1:3], 15, replace = TRUE), nrow = 5, ncol = 3)
x
     [,1] [,2] [,3]
[1,] "B"  "C"  "C" 
[2,] "C"  "A"  "B" 
[3,] "B"  "C"  "C" 
[4,] "C"  "A"  "A" 
[5,] "B"  "A"  "A" 
dput(x)
structure(c("B", "C", "B", "C", "B", "C", "A", "C", "A", "A", 
"C", "B", "C", "A", "A"), .Dim = c(5L, 3L))

Created on 2019-02-27 by the reprex package (v0.2.1)

zkamvar commented 5 years ago

A NEW CHALLENGER APPROACHES:

── 1. Failure: mlg.filter can remember things (@test-filter.R#157)  ────────────
nmll(gc) not equal to 58.
1/1 mismatches
[1] 48 - 58 == -10
── 2. Failure: the mean of the distribution is near the observed value of ia (@t
`rdsa` not equal to mean(jrdsa).
1/1 mismatches
[1] 0.345 - 0.346 == -0.00149
── 3. Failure: mlg.filter will reduce the number of multilocus lineages (@test-s
nmll(sc) not equal to 24.
1/1 mismatches
[1] 25 - 24 == 1
── 4. Failure: win.ia produces expected results (@test-values.R#331)  ──────────
`win.pos` not equivalent to `pos.res`.
34/34 mismatches (average diff: 0.0406)
[1]  0.006734 -  0.04558 == -0.03885
[2] -0.070133 - -0.12165 ==  0.05152
[3] -0.000318 - -0.00595 ==  0.00564
[4] -0.005159 -  0.00808 == -0.01324
[5] -0.041261 - -0.01684 == -0.02442
[6]  0.019504 - -0.00529 ==  0.02480
[7]  0.017314 - -0.00898 ==  0.02629
[8] -0.005025 - -0.01274 ==  0.00771
[9] -0.030357 - -0.04491 ==  0.01455
...
── 5. Failure: win.ia produces expected results (@test-values.R#332)  ──────────
`win.nopos` not equivalent to `nopos.res`.
3/4 mismatches (average diff: 0.0056)
[2] 0.0344 - 0.0335 ==  0.000887
[3] 0.2391 - 0.2266 ==  0.012512
[4] 0.1705 - 0.1739 == -0.003410
── 6. Failure: samp.ia works (@test-values.R#392)  ─────────────────────────────
`pos.res` not equivalent to c(0.0754028380744677, 0.0178846504949451).
2/2 mismatches (average diff: 0.0699)
[1] 0.105 - 0.0754 == 0.0299
[2] 0.128 - 0.0179 == 0.1099
══ testthat results  ══���════════════════════════════════════════════════════════
OK: 959 SKIPPED: 0 FAILED: 6
1. Failure: mlg.filter can remember things (@test-filter.R#157) 
2. Failure: the mean of the distribution is near the observed value of ia (@test-jackia.R#37) 
3. Failure: mlg.filter will reduce the number of multilocus lineages (@test-snpclone.R#61) 
4. Failure: win.ia produces expected results (@test-values.R#331) 
5. Failure: win.ia produces expected results (@test-values.R#332) 
6. Failure: samp.ia works (@test-values.R#392) 

https://travis-ci.org/grunwaldlab/poppr/jobs/502087525#L2993