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

devtools::test() produces error "Error in save(iraceResults, file = logfile, version = 3L): (converted from warning) 'package:irace' may not be available when loading" #2044

Open
MLopez-Ibanez opened this issue Dec 25, 2024 · 2 comments

Comments

@MLopez-Ibanez
Copy link

If I run "R CMD check" I cannot see any warning or error, but running devtools::test() or testthat::test_local(stop_on_failure = TRUE) produces the following error:

Error in `save(iraceResults, file = logfile, version = 3L)`: (converted from warning) 'package:irace' may not be available when loading

Package irace is the package that I am testing. I ran the same code outside of testthat and there is no warning or error.

Warning (test-capping.R:20:3): irace_capping_xy maxTime = 1000
'package:irace' may not be available when loading
Backtrace:
     ▆
  1. ├─testthat::expect_warning(irace_capping_xy(maxTime = 1000), "boundMax = 80 is too large, using 5 instead") at test-capping.R:20:3
  2. │ └─testthat:::expect_condition_matching(...)
  3. │   └─testthat:::quasi_capture(...)
  4. │     ├─testthat (local) .capture(...)
  5. │     │ └─base::withCallingHandlers(...)
  6. │     └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
  7. └─irace_capping_xy(maxTime = 1000)
  8.   └─irace::irace(scenario = scenario) at tests/testthat/helper-common.R:153:3
  9.     └─irace:::irace_common(scenario, simple = TRUE) at git/R/irace.R:598:10
 10.       └─irace:::irace_run(scenario = scenario) at git/R/irace.R:617:3
 11.         └─irace:::elitist_race(...) at git/R/irace.R:1149:5
 12.           └─irace:::race_wrapper(...) at git/R/race.R:961:5
 13.             └─race_state$update_race_experiment_log(target_output, scenario) at git/R/race.R:125:3
 14.               └─irace:::save_irace_logfile(iraceResults, logfile = scenario$logFile) at git/R/race_state.R:118:8
 15.                 └─base::save(iraceResults, file = logfile, version = 3L) at git/R/utils.R:503:3

Error (test-capping.R:20:3): irace_capping_xy maxTime = 1000
Error in `save(iraceResults, file = logfile, version = 3L)`: (converted from warning) 'package:irace' may not be available when loading
Backtrace:
     ▆
  1. ├─testthat::expect_warning(irace_capping_xy(maxTime = 1000), "boundMax = 80 is too large, using 5 instead") at test-capping.R:20:3
  2. │ └─testthat:::expect_condition_matching(...)
  3. │   └─testthat:::quasi_capture(...)
  4. │     ├─testthat (local) .capture(...)
  5. │     │ └─base::withCallingHandlers(...)
  6. │     └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
  7. └─irace_capping_xy(maxTime = 1000)
  8.   └─irace::irace(scenario = scenario) at tests/testthat/helper-common.R:153:3
  9.     └─irace:::irace_common(scenario, simple = TRUE) at git/R/irace.R:598:10
 10.       └─irace:::irace_run(scenario = scenario) at git/R/irace.R:617:3
 11.         └─irace:::save_irace_logfile(iraceResults, logfile = scenario$logFile) at git/R/irace.R:893:5
@MLopez-Ibanez
Copy link
Author

I found a work-around.

iraceResults stores a function defined in tests/testthat/helper-common.R. For some reason, this function's environment is <environment: package:irace>. If I modify its environment as follows:

  targetRunner <- target_runner_capping_xy
  environment(targetRunner) <- globalenv()

Then everything works without warning or error.

@MLopez-Ibanez
Copy link
Author

Then everything works without warning or error.

But it breaks parallel execution within R CMD check. Another strange thing I noticed. When running under R CMD check, the environment of target_runner_capping_xy is <environment: namespace:irace>. When running under devtools::test() it is <environment: package:irace>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant