Run Code 'With' Temporarily Modified Global State
Overview
A set of functions to run code 'with' safely and temporarily modified global state. Many of these functions were originally a part of the 'devtools' package, this provides a simple package with limited dependencies to provide access to these functions.
- Fixes for CRAN checks.
- Fixed issue that prevented
local_seed()from preserving the seed (#286, @BjarkeHautop). Note: If you had before: ``r test_that("A", { withr::local_seed(1) # Seeds locally runif(...) }) test_that("B", { runif(...) # NO seed of its own })`` Before the fix, the test "B" was accidentally seeded by "A". Now it needs to be seeded on its own.
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-04
- NOTE12 OK, 1 NOTE2026-08-01
- OK13 OK2026-06-22
- ERROR13 OK, 1 ERROR2026-03-10
Documentation
- Help pages
- 28 (4 internal)includes a package overview page
- Examples that run
- 95%20 run in a plain check · 1 never run
- Exported functions with examples
- 77%
- Documented parameters
- 85%
- Return-value docs
- 81%
- Help pages citing references
- 0%
Downloads
Repository
- PRs merged (all time)
- 90%
- Median days to close, 50 most recently updated closed issues
- 84
- Median days to close, 50 most recently updated closed PRs
- 1
Stars over time
Forks over time
Releases over time
Issues over time
PRs over time
Commits over time
Commit identities over time
12 development-tooling and community-health practices detected across 5 families in the upstream repository
Checks run against github.com/r-lib/withr on 2026-10-18.
The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel
GitHub Pages site last deployed 2026-10-12 · The repository has a site deploy workflow
pkgdown site last built 2026-06-22
Show all practicesHide 1 practice
Dependencies
Installing withr adds no packages beyond those that come with R.
Show the 48 most downloaded dependentsHide the 48 most downloaded dependents
and 350 more dependents and 1,231 packages that suggest it on CRAN ↗
Code & Tests
People & History
Previously maintained by Jim Hester (1.0.0 to 2.4.2).
Pick two releases to compare their code metrics.
- 3.0.3Latest
- RR 4.6.0 released · 2026-04-24
- RR 4.5.0 released · 2025-04-11
- 3.0.22024-10-28 · diff ↗
- 3.0.12024-07-31 · diff ↗
- RR 4.4.0 released · 2024-04-24
- 3.0.0
- 2.5.22023-10-30 · diff ↗
- 2.5.12023-09-26 · diff ↗
- RR 4.3.0 released · 2023-04-21
- RR 4.2.0 released · 2022-04-22
- 2.5.02022-03-03 · diff ↗
- 2.4.3
- RR 4.1.0 released · 2021-05-18
- 2.4.22021-04-18 · diff ↗
- 2.4.12021-01-26 · diff ↗
Show 16 earlier eventsHide 16 earlier events
- 2.4.0
- 2.3.0
- RR 4.0.0 released · 2020-04-24
- 2.2.02020-04-21 · diff ↗ ·
added 8 exports
deferred_clear, deferred_run, local_rng_version, local_timezone, makevars_user, with_rng_version, with_tempdir, with_timezone - RR 3.6.0 released · 2019-04-26
- RR 3.5.0 released · 2018-04-23
- 2.1.2
- 2.1.1
- 2.1.02017-11-01 · diff ↗ ·
added 32 exports
local_bmp, local_cairo_pdf, local_cairo_ps, local_connection, local_db_connection, local_environment, local_jpeg, local_namespace, local_package, local_pdf, local_png, local_postscript, local_svg, local_tempfile, local_tiff, local_xfig, with_bmp, with_cairo_pdf, with_cairo_ps, with_connection, with_db_connection, with_environment, with_jpeg, with_namespace, with_package, with_pdf, with_png, with_postscript, with_svg, with_tempfile and 2 more - 2.0.02017-07-29 · diff ↗ ·
added 16 exports
defer, defer_parent, local_, local_collate, local_dir, local_envvar, local_libpaths, local_locale, local_message_sink, local_options, local_output_sink, local_par, local_path, local_temp_libpaths, with_preserve_seed, with_seed - RR 3.4.0 released · 2017-04-21
- 1.0.22016-06-20 · diff ↗
- RR 3.3.0 released · 2016-05-03
- 1.0.1
- 1.0.02015-09-23
- RR 3.2.0 released · 2015-04-16
Package metadata
- First published
- 2015-09-23
- Total releases
- 20 / 11 yrs
- License
- MIT + file LICENSE OSI · relicensed from GPL (>= 2) in 2.4.0
- Minimum R
- ≥ 3.6.0
- Download size
- 102 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("withr")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-21, which the citation names so these numbers can be found later. More on citing and the projects behind them.