Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix R CMD check error on M1mac #5

Closed
kwstat opened this issue Sep 14, 2021 · 2 comments
Closed

Fix R CMD check error on M1mac #5

kwstat opened this issue Sep 14, 2021 · 2 comments
Labels

Comments

@kwstat
Copy link
Owner

kwstat commented Sep 14, 2021

From CRAN:

Check: tests
Result: ERROR
     Running ‘testthat.R’ [1s/1s]
    Running the tests in ‘tests/testthat.R’ failed.
    Last 13 lines of output:
     PC 5 starting column: 2..
     ══ Skipped tests ═══════════════════════════════════════════════════════════════
     • empty test (2)
    
     ══ Failed tests ════════════════════════════════════════════════════════════════
     ── Failure (test-uscrime.R:68:3): SVD, NIPALS and EMPCA results match for complete uscrime data ──
     `avg_angle` is not strictly less than `tol`. Difference: NaN
     Backtrace:
     █
     1. └─nipals:::expect_aligned(m1s$u, m1e$scores) test-uscrime.R:68:2
     2. └─testthat::expect_lt(avg_angle, tol) setup-expectations.R:22:2
    
     [ FAIL 1 | WARN 1 | SKIP 2 | PASS 27 ]
     Error: Test failures
     Execution halted
Flavor: r-release-macos-arm64

Note: arm64 (aka 'Apple Silicon' aka 'M1') Mac.

@kwstat kwstat added the bug label Sep 14, 2021
@kwstat
Copy link
Owner Author

kwstat commented Sep 14, 2021

rhub::platforms() gives (among others):

macos-highsierra-release:
  macOS 10.13.6 High Sierra, R-release, brew
macos-highsierra-release-cran:
  macOS 10.13.6 High Sierra, R-release, CRAN's setup
macos-m1-bigsur-release:
  Apple Silicon (M1), macOS 11.6 Big Sur, R-release

@kwstat
Copy link
Owner Author

kwstat commented Sep 14, 2021

This was painfull hard to diagnose, so here are some things I learned.

  1. This error was only happening on Mac M1. You can test only that platform on Rhub:
rhub::check("nipals_0.7.tar.gz", platform = "macos-m1-bigsur-release")
  1. Rhub truncates the test output to the last 13 lines. You can get around that by setting an environment variable to disable truncation:
rhub::check("nipals_0.7.tar.gz", env_vars = c(`_R_CHECK_TESTS_NLINES_` = '0'),
            platform = "macos-m1-bigsur-release")
  1. Due to floating point error, the dot product of two nearly-parallel vectors can end up outside [-1,1]. Previously I checked for this condition before calling acos() to find the angle between the vectors:
acos( abs(dotprod) - .Machine$double.eps )

But on this Mac M1 machine for this problem, print(dotprod, digits=17) = -1.00000000000000044 and subtracting .Machine$double.eps was not sufficient to bring the value inside [-1,1].

(abs(-1.00000000000000044) - .Machine$double.eps ) < 1
# FALSE

So I switched to ensuring the value is inside [-1,1] with

pmin(abs(dotprod), 1)

@kwstat kwstat closed this as completed Sep 15, 2021
kwstat added a commit that referenced this issue Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant