twolodzko / kernelboot

Smoothed bootstrap and functions for sampling from kernel densities
3 stars 1 forks source link

TESTS: Wrong assertion when availableCores() == 1 #2

Closed HenrikBengtsson closed 6 years ago

HenrikBengtsson commented 6 years ago

Hi, while running revdep checks on globals packages in single-core mode, I got:

 ERROR
Running the tests in ‘tests/test_parallel.R’ failed.
Complete output:
  > 
  > library("kernelboot")
  > 
  > # simply check if it fails
  > 
  > stopifnot( kernelboot(mtcars, function(data) coef(lm(mpg ~ disp + hp + drat, data = data)),
  +                       R = 10, parallel = TRUE)$param$parallel )
  Error: kernelboot(mtcars, function(data) coef(lm(mpg ~ disp + hp + drat,  .... is not TRUE
  Execution halted

This is because tests/test_parallel.R:

stopifnot( kernelboot(mtcars, function(data) coef(lm(mpg ~ disp + hp + drat, data = data)),
R = 10, parallel = TRUE)$param$parallel )

assumes that availableCores() > 1. See also https://github.com/twolodzko/kernelboot/blob/master/R/kernelboot.R#L355-L368

twolodzko commented 6 years ago

Thanks, I'll fix that!

twolodzko commented 6 years ago

@HenrikBengtsson I don't know how could I test it on single-core setting, so could you please give me some hints, or confirm that now it the tests work fine?

HenrikBengtsson commented 6 years ago

If you set (parallel's) env var MC_CORES to a single core, then future will acknowledge that, e.g.

$ export MC_CORES=1
$ Rscript -e "future::availableCores()"
mc.cores 
       1

This should also work when you do:

$ export MC_CORES=1
$ R CMD check --as-cran kernelboot_x.y.z.tar.gz
HenrikBengtsson commented 6 years ago

Or, in your R test script, you can use:

options(mc.cores = 1L)
twolodzko commented 6 years ago

@HenrikBengtsson thanks! I don't feel that this is urgent to update on CRAN, does it affect revdeps of your package?

HenrikBengtsson commented 6 years ago

Correct - nothing urgent, just though you might wanna know about it since the fix is simple.