From 27e7950a390fce7c4b006b566e97e034b927bc73 Mon Sep 17 00:00:00 2001 From: Tan Ho <38083823+tanho63@users.noreply.github.com> Date: Tue, 8 Aug 2023 09:34:08 -0400 Subject: [PATCH 1/3] Add core limit for tests --- tests/testthat/setup.R | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/testthat/setup.R diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R new file mode 100644 index 0000000..ec28268 --- /dev/null +++ b/tests/testthat/setup.R @@ -0,0 +1,6 @@ +## Limit datatable to two CPU cores for test purposes +# https://github.com/Rdatatable/data.table/issues/5658 + +current_threads <- data.table::getDTthreads() +data.table::setDTthreads(2) +testthat::teardown_env(data.table::setDTthreads(current_threads)) From 09599b1416abf01f188e6061c0684fc39d9b8f16 Mon Sep 17 00:00:00 2001 From: Tan Ho <38083823+tanho63@users.noreply.github.com> Date: Tue, 8 Aug 2023 11:15:07 -0400 Subject: [PATCH 2/3] Update setup.R --- tests/testthat/setup.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index ec28268..300a998 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -3,4 +3,4 @@ current_threads <- data.table::getDTthreads() data.table::setDTthreads(2) -testthat::teardown_env(data.table::setDTthreads(current_threads)) +withr::defer(data.table::setDTthreads(current_threads), testthat::teardown_env()) From 3ff4eeb6ca23f1657487fb831c4932cfcc347e19 Mon Sep 17 00:00:00 2001 From: Tan Ho <38083823+tanho63@users.noreply.github.com> Date: Wed, 9 Aug 2023 09:56:48 -0400 Subject: [PATCH 3/3] Update tests/testthat/setup.R Co-authored-by: mrcaseb <38586519+mrcaseb@users.noreply.github.com> --- tests/testthat/setup.R | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 300a998..9ee7b5c 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -1,6 +1,11 @@ -## Limit datatable to two CPU cores for test purposes -# https://github.com/Rdatatable/data.table/issues/5658 +# CRAN incoming checks can fail if examples use more than 2 cores. +# We can run in this problem by using data.table https://github.com/Rdatatable/data.table/issues/5658 +# R CMD Check throws the NOTE because CRAN sets +# _R_CHECK_EXAMPLE_TIMING_CPU_TO_ELAPSED_THRESHOLD_ to "2.5" +# which means "more than two cores are running". +# We check for this specific environment variable and run the nflreadr helper +# if it is set to any value +cpu_threshold <- as.numeric(Sys.getenv("_R_CHECK_EXAMPLE_TIMING_CPU_TO_ELAPSED_THRESHOLD_", + NA_character_)) -current_threads <- data.table::getDTthreads() -data.table::setDTthreads(2) -withr::defer(data.table::setDTthreads(current_threads), testthat::teardown_env()) +if (!is.na(cpu_threshold)) nflreadr::.for_cran()