diff --git a/NAMESPACE b/NAMESPACE index dc0dded..ee502fe 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -46,7 +46,6 @@ export(repo_get) export(repo_resolve) export(repo_status) export(with_repo) -if (getRversion() >= "4.0.0") importFrom(tools, R_user_dir) importFrom(R6,R6Class) importFrom(tools,file_ext) importFrom(utils,URLencode) diff --git a/R/aaa-async.R b/R/aaa-async.R index ac3da72..e5fc7d1 100644 --- a/R/aaa-async.R +++ b/R/aaa-async.R @@ -310,7 +310,7 @@ async_env <- new.env(parent = emptyenv()) async_env$loops <- list() get_default_event_loop <- function() { - num_loops <- length(async_env$loops) + num_loops <- length2(async_env$loops) if (num_loops == 0) { err <- make_error( "You can only call async functions from an async context", @@ -321,6 +321,10 @@ get_default_event_loop <- function() { async_env$loops[[num_loops]] } +# Mockable version of length. +length2 <- function(x) { + length(x) +} push_event_loop <- function() { num_loops <- length(async_env$loops) diff --git a/R/cache-dirs.R b/R/cache-dirs.R index 9bca8dd..5b8880c 100644 --- a/R/cache-dirs.R +++ b/R/cache-dirs.R @@ -103,6 +103,8 @@ win_path_local <- function() { if (getRversion() < "4.0.0") { R_user_dir <- my_R_user_dir +} else { + R_user_dir <- tools::R_user_dir } cleanup_old_cache_dir <- function(force = FALSE) { diff --git a/R/mocks.R b/R/mocks.R index 12e232a..332b2ce 100644 --- a/R/mocks.R +++ b/R/mocks.R @@ -1,11 +1,9 @@ # Define these objects so they can be mocked in tests. -interactive <- interactive +interactive <- base::interactive readline <- function(prompt = "") { - readline + base::readline(prompt = prompt) } -length <- length Sys.info <- function() { - Sys.info + base::Sys.info() } -R_user_dir <- R_user_dir -getRversion <- getRversion +getRversion <- base::getRversion diff --git a/tests/async/test-synchronise.R b/tests/async/test-synchronise.R index 3453c4c..0a51e2f 100644 --- a/tests/async/test-synchronise.R +++ b/tests/async/test-synchronise.R @@ -1,7 +1,7 @@ test_that("error if async function is called from sync context", { - local_mocked_bindings(length = function(...) 0) + local_mocked_bindings(length2 = function(x) 0) expect_error( get_default_event_loop(), class = "async_synchronization_barrier_error")