dpc10ster / RJafroc

Artificial Intelligence: Evaluating AI, optimizing AI
19 stars 8 forks source link

rhub check failures 2 of xx on cran4b branch: 0.7, 0.2 and 0.1 not summing to unity! #76

Closed dpc10ster closed 2 years ago

dpc10ster commented 2 years ago

File inst\cranSubmission\cranSubmission.R is same as in previous issue (rhub check failures 2 of xx on cran4a branch).

Code for this issue is on branch cran4b.

The difference is in file SsFrocNhRsmModel.R: currently the relevant lines are:

 if (sum(lesDistr) != 1.0) {
    errMsg <- ""
    for (i in 1:length(lesDistr)) errMsg <- paste0(errMsg, sprintf("%10.5f", lesDistr[i]))
    errMsg <- paste0("The lesion distribution vector must sum to unity:", errMsg)
    stop(errMsg)
  }

vs. previous code

  chk1 <- abs(sum(lesDistr) - 1.0)
  if (chk1 > 1e-5) {
    errMsg <- ""
    for (i in 1:length(lesDistr)) errMsg <- paste0(errMsg, sprintf("%10.5f", lesDistr[i]))
    errMsg <- paste0(errMsg, sprintf(".  Difference =   %10.5e", chk1))
    errMsg <- paste0("The lesion distribution vector must sum to unity:", errMsg)
    stop(errMsg)
  }

And here is the relevant output:

     ══ Failed tests ════════════════════════════════════════════════════════════════
     ── Error (test-SsSampleSizeFroc.R:21:3): Sample Size FROC ──────────────────────
     Error in `SsFrocNhRsmModel(frocNhData, lesDistr = lesDistr)`: The lesion distribution vector must sum to unity:   0.70000   0.20000   0.10000
     Backtrace:
         ▆
      1. └─RJafroc::SsFrocNhRsmModel(frocNhData, lesDistr = lesDistr) at test-SsSampleSizeFroc.R:21:2

     [ FAIL 1 | WARN 1 | SKIP 8 | PASS 1462 ]
     Error: Test failures
     Execution halted
✔  checking for unstated dependencies in vignettes
✔  checking package vignettes in ‘inst/doc’
─  checking running R code from vignettes
     ‘Ch19Vig1FrocSampleSize.Rmd’ using ‘UTF-8’... OK
     ‘Ch19Vig2FrocSampleSize.Rmd’ using ‘UTF-8’... OK
    NONE
W  checking re-building of vignette outputs (5s)
   Error(s) in re-building vignettes:
     ...
   --- re-building ‘Ch19Vig1FrocSampleSize.Rmd’ using rmarkdown
   Quitting from lines 145-155 (Ch19Vig1FrocSampleSize.Rmd) 
   Error: processing vignette 'Ch19Vig1FrocSampleSize.Rmd' failed with diagnostics:
   polygon edge not found
   --- failed re-building ‘Ch19Vig1FrocSampleSize.Rmd’

   --- re-building ‘Ch19Vig2FrocSampleSize.Rmd’ using rmarkdown
   Quitting from lines 37-44 (Ch19Vig2FrocSampleSize.Rmd) 
   Error: processing vignette 'Ch19Vig2FrocSampleSize.Rmd' failed with diagnostics:
   The lesion distribution vector must sum to unity:   0.70000   0.20000   0.10000
   --- failed re-building ‘Ch19Vig2FrocSampleSize.Rmd’

   SUMMARY: processing the following files failed:
     ‘Ch19Vig1FrocSampleSize.Rmd’ ‘Ch19Vig2FrocSampleSize.Rmd’

   Error: Vignette re-building failed.
   Execution halted

Cannot figure out why sum of 0.70000 0.20000 0.10000 is not unity.

pwep commented 2 years ago

Interesting. We have been in this bit of code before with issue #70.

dpc10ster commented 2 years ago

yes; but this error is occurring in standard R code, not in testthat function: sum(lesDistr) != 1.0; I also tried sum(lesDistr) != 1 with same error; the only way to get past this "error" is to test the absolute value of the difference; makes no sense to me;

pwep commented 2 years ago

Just checking in. Still working on trying to solve this one. A tricky issue.

dpc10ster commented 2 years ago

Thanks. Take your time;

On Sun, Jul 17, 2022 at 8:06 AM Peter Phillips @.***> wrote:

Just checking in. Still working on trying to solve this one. A tricky issue.

— Reply to this email directly, view it on GitHub https://github.com/dpc10ster/RJafroc/issues/76#issuecomment-1186498358, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH4NJRBQBX7SWCE2T52EB3LVUPZMJANCNFSM53MHIFJA . You are receiving this because you authored the thread.Message ID: @.***>

pwep commented 2 years ago

OK - try this:

The line if (sum(lesDistr) != 1.0) looks like a valid comparison, but a more robust alternative is:

if ( !isTRUE( all.equal( sum(lesDistr), 1.0 ) ) )

...as mentioned in https://search.r-project.org/R/refmans/base/html/all.equal.html. The isTrue() wrapping function is important.

I'm hopeful that this will fix the sum-to-unity check.

dpc10ster commented 2 years ago

I have tested on "macos-m1-bigsur-release" and the sum error has gone away with your fix. I am surprised that we have to go through such contortions to test the equality of two numeric values.

The other error, i.e., the ggplot2 error in building vignette 1, will go away when we delete the 2 vignettes. I need to put a link in the R file on where to find these in the bookdown version.

dpc10ster commented 2 years ago

This issue reared its ugly head in one more place; see 9c686aba7f2697493c959464ea007162dbc07bc7 With this fix this branch builds OK on Apple Silicon (M1), macOS 11.6 Big Sur, R-release: