diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 5a837958..3bbe3005 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -8,7 +8,6 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] name: R-CMD-check diff --git a/DESCRIPTION b/DESCRIPTION index 94ae87e0..41646c66 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: withr Title: Run Code 'With' Temporarily Modified Global State -Version: 2.5.0 +Version: 2.5.1 Authors@R: c(person(given = "Jim", family = "Hester", @@ -8,7 +8,7 @@ Authors@R: person(given = "Lionel", family = "Henry", role = c("aut", "cre"), - email = "lionel@rstudio.com"), + email = "lionel@posit.co"), person(given = "Kirill", family = "Müller", role = "aut", @@ -30,7 +30,7 @@ Authors@R: person(given = "Richard", family = "Cotton", role = "ctb"), - person(given = "RStudio", + person(given = "Posit Software, PBC", role = c("cph", "fnd"))) Description: A set of functions to run code 'with' safely and temporarily modified global state. Many of these functions were diff --git a/NEWS.md b/NEWS.md index 94c9c60f..21741f06 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# withr 2.5.1 + +* Fixes for CRAN checks. + + # withr 2.5.0 * `defer()` and all `local_*()` functions now work when run inside of diff --git a/R/timezone.R b/R/timezone.R index 480baa6e..57186f3d 100644 --- a/R/timezone.R +++ b/R/timezone.R @@ -17,7 +17,7 @@ #' @examples #' Sys.time() #' with_timezone("Europe/Paris", print(Sys.time())) -#' with_timezone("US/Pacific", print(Sys.time())) +#' with_timezone("America/Los_Angeles", print(Sys.time())) #' with_timezone <- function(tz, code) { reset_timezone() @@ -34,7 +34,7 @@ with_timezone <- function(tz, code) { #' } #' #' fun2 <- function() { -#' local_timezone("US/Pacific") +#' local_timezone("America/Los_Angeles") #' print(Sys.time()) #' } #' Sys.time() diff --git a/cran-comments.md b/cran-comments.md index 141f996a..32cf57a1 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,9 +1 @@ -## R CMD check results -There were no NOTEs, ERRORs or WARNINGs. - -## revdepcheck results - -We checked 324 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. - - * We saw 0 new problems - * We failed to check 0 packages +Fixes the timezone and translation issues diff --git a/man/with_tempfile.Rd b/man/with_tempfile.Rd index fd862168..90ef5d44 100644 --- a/man/with_tempfile.Rd +++ b/man/with_tempfile.Rd @@ -55,9 +55,9 @@ local_tempdir( \item{pattern}{a non-empty character vector giving the initial part of the name.} -\item{tmpdir}{a non-empty character vector giving the directory name} +\item{tmpdir}{a non-empty character vector giving the directory name.} -\item{fileext}{a non-empty character vector giving the file extension} +\item{fileext}{a non-empty character vector giving the file extension.} \item{lines}{Optionally, supply lines to be fed into} diff --git a/man/with_timezone.Rd b/man/with_timezone.Rd index a816e593..7f77b413 100644 --- a/man/with_timezone.Rd +++ b/man/with_timezone.Rd @@ -25,16 +25,16 @@ argument. Change the time zone, and restore it afterwards. } \details{ -\code{with_time_zone()} runs the code with the specified time zone and +\code{with_timezone()} runs the code with the specified time zone and resets it afterwards. -\code{local_time_zone()} changes the time zone for the caller +\code{local_timezone()} changes the time zone for the caller execution environment. } \examples{ Sys.time() with_timezone("Europe/Paris", print(Sys.time())) -with_timezone("US/Pacific", print(Sys.time())) +with_timezone("America/Los_Angeles", print(Sys.time())) fun1 <- function() { local_timezone("CET") @@ -42,7 +42,7 @@ fun1 <- function() { } fun2 <- function() { - local_timezone("US/Pacific") + local_timezone("America/Los_Angeles") print(Sys.time()) } Sys.time() diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 6c6627f8..8b5b8146 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -37,3 +37,11 @@ skip_if_cannot_knit <- function() { skip_if_not_installed("rmarkdown") skip_if(!rmarkdown::pandoc_available()) } + +# Need to also specify `LC_ALL` because `LANGUAGE` is ignored when +# `LANG` is set (here via `LC_ALL`) to `C` or `C.UTF-8` +with_lang <- function(lc, language, expr) { + withr::local_envvar(c(LC_ALL = lc)) + withr::local_language(language) + expr +} diff --git a/tests/testthat/test-language.R b/tests/testthat/test-language.R index 5dc2bd57..3c2935fd 100644 --- a/tests/testthat/test-language.R +++ b/tests/testthat/test-language.R @@ -1,13 +1,13 @@ test_that("can temporarily change language", { skip_if_not(has_nls()) - expect_error(with_language("en", mean[[1]]), "not subsettable") - expect_error(with_language("fr", mean[[1]]), "non indi\u00e7able") - expect_error(with_language("es", mean[[1]]), "no es subconjunto") + expect_error(with_lang("en_GB", "en", mean[[1]]), "not subsettable") + expect_error(with_lang("fr_FR", "fr", mean[[1]]), "non indi\u00e7able") + expect_error(with_lang("es_ES", "es", mean[[1]]), "no es subconjunto") # can use either _ or - - expect_error(with_language("pt_BR", mean[[1]]), "não possível dividir") - expect_error(with_language("pt-BR", mean[[1]]), "não possível dividir") + expect_error(with_lang("pt_BR", "pt_BR", mean[[1]]), "não possível dividir") + expect_error(with_lang("pt_BR", "pt-BR", mean[[1]]), "não possível dividir") }) test_that("warns if LANG=C", { diff --git a/tests/testthat/test-timezone.R b/tests/testthat/test-timezone.R index 481f2d7e..119a4449 100644 --- a/tests/testthat/test-timezone.R +++ b/tests/testthat/test-timezone.R @@ -5,7 +5,7 @@ describe("with_timezone", { expect_true( with_timezone("CET", format(Sys.time(), "%Z")) %in% c("CET", "CEST")) expect_true( - with_timezone("US/Pacific", format(Sys.time(), "%Z")) %in% c("PDT", "PST")) + with_timezone("America/Los_Angeles", format(Sys.time(), "%Z")) %in% c("PDT", "PST")) }) @@ -15,7 +15,7 @@ describe("with_timezone", { expect_identical(cur, Sys.timezone()) cur <- Sys.timezone() - expect_equal(with_timezone("US/Pacific", Sys.timezone()), "US/Pacific") + expect_equal(with_timezone("America/Los_Angeles", Sys.timezone()), "America/Los_Angeles") expect_identical(cur, Sys.timezone()) }) }) @@ -30,8 +30,8 @@ describe("local_timezone", { with_timezone("CET", Sys.timezone()), fun("CET")) expect_identical( - with_timezone("US/Pacific", Sys.timezone()), - fun("US/Pacific")) + with_timezone("America/Los_Angeles", Sys.timezone()), + fun("America/Los_Angeles")) }) it("restores the time zone", { @@ -42,7 +42,7 @@ describe("local_timezone", { } fun("CET") expect_identical(cur, Sys.timezone()) - fun("US/Pacific") + fun("America/Los_Angeles") expect_identical(cur, Sys.timezone()) }) })