vincentarelbundock / tinysnapshot

Snapshots for unit tests using the tinytest framework for `R`. Includes expectations to test base `R` and `ggplot2` plots as well as console output from `print()`.
11 stars 0 forks source link

CRAN magick + OpenMP gotcha #13

Open grantmcdermott opened 9 months ago

grantmcdermott commented 9 months ago

Flavor: r-devel-linux-x86_64-debian-gcc Check: tests, Result: NOTE Running 'tinytest.R' [53s/11s] Running R code in 'tinytest.R' had CPU time 5 times elapsed time

Was banging my head against this infamous precheck blocker after submitting ggfixest to CRAN. I finally realised it was due to (tinysnapshot dependency) magick's hidden OpenMP invocation. Also reflects the fact that I have a lot of snapshot tests.

The solution is to add something like the following to one's test suite.

# Throttle CPU threads if R CMD check (for CRAN)
if (any(grepl("_R_CHECK", names(Sys.getenv()), fixed = TRUE))) {
    if (requireNamespace("magick", quietly = TRUE)) {
        library(magick)
        magick:::magick_threads(1)
    }
}

# Run (tiny)test suite as per usual
if ( requireNamespace("tinytest", quietly=TRUE) ){
  tinytest::test_package("YOUR_PACKAGE_NAME")
}

Might be noting in your README guide? Happy to put in a PR if you like the idea.

vincentarelbundock commented 9 months ago

Aaah thanks!

I don't really understand the full context,.but that sounds like useful background, so I'm happy to merge whatever you think is useful.