From eb94a951d2625ea12e1cf135516c85ee62e794cb Mon Sep 17 00:00:00 2001 From: wlandau Date: Tue, 23 May 2023 09:04:08 -0400 Subject: [PATCH] CRAN patch 3 --- DESCRIPTION | 2 +- NEWS.md | 4 ++-- R/class_runtime.R | 9 +++++++-- R/utils_time.R | 16 +++++++--------- tests/testthat/test-class_aws.R | 1 + tests/testthat/test-class_gcp.R | 1 + tests/testthat/test-class_runtime.R | 8 ++++++++ tests/testthat/test-utils_time.R | 10 ++++++++++ 8 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 tests/testthat/test-utils_time.R diff --git a/DESCRIPTION b/DESCRIPTION index 33003e5b8..7c6c259b3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally The methodology in this package borrows from GNU 'Make' (2015, ISBN:978-9881443519) and 'drake' (2018, ). -Version: 1.1.2.9000 +Version: 1.1.3 License: MIT + file LICENSE URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets BugReports: https://github.com/ropensci/targets/issues diff --git a/NEWS.md b/NEWS.md index 682015f61..9f19c5eed 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ -# targets 1.1.2.9000 - +# targets 1.1.3 +* Decide on `nanonext` usage in `time_seconds_local()` at runtime and not installation time. That way, if `nanonext` is removed after `targets` is installed, functions in `targets` still work. Fixes the CRAN issues seen in `tarchetypes`, `jagstargets`, and `gittargets`. # targets 1.1.2 diff --git a/R/class_runtime.R b/R/class_runtime.R index 868b98f8c..0a5f6f614 100644 --- a/R/class_runtime.R +++ b/R/class_runtime.R @@ -9,7 +9,8 @@ runtime_new <- function( gcp_auth = NULL, file_exist = NULL, file_info = NULL, - file_info_exist = NULL + file_info_exist = NULL, + nanonext = NULL ) { force(target) force(frames) @@ -22,6 +23,7 @@ runtime_new <- function( force(file_exist) force(file_info) force(file_info_exist) + force(nanonext) environment() } @@ -61,7 +63,6 @@ runtime_validate <- function(x) { if (!is.null(x$gcp_auth)) { tar_assert_scalar(x$gcp_auth) tar_assert_lgl(x$gcp_auth) - tar_assert_nzchar(x$gcp_auth) } if (!is.null(x$file_exist)) { tar_assert_envir(x$file_exist) @@ -73,6 +74,10 @@ runtime_validate <- function(x) { if (!is.null(x$file_info_exist)) { tar_assert_envir(x$file_info_exist) } + if (!is.null(x$nanonext)) { + tar_assert_scalar(x$nanonext) + tar_assert_lgl(x$nanonext) + } } #' @title Get the `tar_runtime` object. diff --git a/R/utils_time.R b/R/utils_time.R index d75eeee8e..9aebff019 100644 --- a/R/utils_time.R +++ b/R/utils_time.R @@ -14,15 +14,13 @@ time_seconds <- function() { ) } -# not possible to cover both cases -# nocov start -if (length(find.package("nanonext", quiet = TRUE)) > 0L) { - time_seconds_local <- function() { - nanonext::mclock() / 1e3 +time_seconds_local <- function() { + if (is.null(tar_runtime$nanonext)) { + tar_runtime$nanonext <- rlang::is_installed("nanonext") } -} else { - time_seconds_local <- function() { + if_any( + tar_runtime$nanonext, + nanonext::mclock() / 1e3, as.numeric(proc.time()["elapsed"]) - } + ) } -# nocov end diff --git a/tests/testthat/test-class_aws.R b/tests/testthat/test-class_aws.R index 4507a674b..0b326d2f5 100644 --- a/tests/testthat/test-class_aws.R +++ b/tests/testthat/test-class_aws.R @@ -95,6 +95,7 @@ tar_test("deprecated aws_* classes", { }) tar_test("package detection", { + skip_cran() target <- tar_target(x, "x_value", format = "feather", repository = "aws") out <- sort(store_get_packages(target$store)) exp <- sort(c("paws", "arrow")) diff --git a/tests/testthat/test-class_gcp.R b/tests/testthat/test-class_gcp.R index c106de553..53eb86c2a 100644 --- a/tests/testthat/test-class_gcp.R +++ b/tests/testthat/test-class_gcp.R @@ -33,6 +33,7 @@ tar_test("store_gcp_version()", { }) tar_test("package detection", { + skip_cran() target <- tar_target(x, "x_value", format = "feather", repository = "gcp") out <- sort(store_get_packages(target$store)) exp <- sort(c("googleCloudStorageR", "arrow")) diff --git a/tests/testthat/test-class_runtime.R b/tests/testthat/test-class_runtime.R index f022a62a2..a8659f274 100644 --- a/tests/testthat/test-class_runtime.R +++ b/tests/testthat/test-class_runtime.R @@ -89,6 +89,14 @@ tar_test("file_info_exist", { expect_silent(runtime_validate(x)) }) +tar_test("nanonext", { + x <- runtime_new() + expect_null(x$nanonext) + x$nanonext <- TRUE + expect_true(x$nanonext) + expect_silent(runtime_validate(x)) +}) + tar_test("validate null fields", { x <- runtime_new() expect_silent(runtime_validate(x)) diff --git a/tests/testthat/test-utils_time.R b/tests/testthat/test-utils_time.R new file mode 100644 index 000000000..01f05e9d1 --- /dev/null +++ b/tests/testthat/test-utils_time.R @@ -0,0 +1,10 @@ +test_that("time_seconds_local()", { + tar_runtime$nanonext <- NULL + for (i in seq_len(4)) { + out <- time_seconds_local() + expect_true(is.numeric(out)) + expect_false(anyNA(out)) + expect_equal(length(out), 1L) + } + expect_equal(2 * 2, 4) +})