-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move withr from imports to suggests (#291)
So we can use pkgload with withr
- Loading branch information
Showing
18 changed files
with
99 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
defer <- function (expr, env = caller_env(), after = FALSE) { | ||
thunk <- as.call(list(function() expr)) | ||
do.call(on.exit, list(thunk, TRUE, after), envir = env) | ||
} | ||
|
||
local_envvar <- function(..., .frame = parent.frame()) { | ||
old <- set_envvar(list(...)) | ||
defer(set_envvar(old), .frame) | ||
|
||
invisible() | ||
} | ||
|
||
local_collate <- function(locale, frame = parent.frame()) { | ||
old <- Sys.getlocale("LC_COLLATE") | ||
defer(Sys.setlocale("LC_COLLATE", old), frame) | ||
Sys.setlocale("LC_COLLATE", locale) | ||
|
||
# From https://github.com/r-lib/withr/blob/v3.0.0/R/locale.R#L51-L55: | ||
# R supports setting LC_COLLATE to C via envvar. When that is the | ||
# case, it takes precedence over the currently set locale. We need | ||
# to set both the envvar and the locale for collate to fully take | ||
# effect. | ||
local_envvar(LC_COLLATE = locale, .frame = frame) | ||
|
||
invisible() | ||
} | ||
|
||
local_dir <- function(path, frame = parent.frame()) { | ||
old <- setwd(path) | ||
defer(setwd(old), frame) | ||
|
||
invisible() | ||
} | ||
|
||
# adapted from withr:::set_envvar | ||
set_envvar <- function(envs) { | ||
if (length(envs) == 0) { | ||
return() | ||
} | ||
|
||
old <- Sys.getenv(names(envs), names = TRUE, unset = NA) | ||
set <- !is.na(envs) | ||
|
||
if (any(set)) do.call("Sys.setenv", as.list(envs[set])) | ||
if (any(!set)) Sys.unsetenv(names(envs)[!set]) | ||
|
||
invisible(old) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
test_that("respects version separator", { | ||
ns <- create_ns_env(test_path("testVersionSep")) | ||
withr::defer(unregister_namespace("testVersionSep")) | ||
defer(unregister_namespace("testVersionSep")) | ||
|
||
expect_equal(getNamespaceInfo(ns, "spec")[["version"]], "0.0.0-9000") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters