Skip to content

Commit

Permalink
Speed up package version check in .rlang_cli_compat() (#1657)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch authored Oct 7, 2023
1 parent 2a831ef commit 7a78dc3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

* `expr_label()` now has back-compatility with respect to changes made by R version 4.4 and `is.atomic(NULL)` (#1655)

* Performance improvement in `.rlang_cli_compat()` (#1657).

# rlang 1.1.1

* `englue()` now allows omitting `{{`. This is to make it easier to
Expand Down
14 changes: 11 additions & 3 deletions R/standalone-cli.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ---
# repo: r-lib/rlang
# file: standalone-cli.R
# last-updated: 2022-09-23
# last-updated: 2023-10-06
# license: https://unlicense.org
# ---
#
Expand All @@ -11,6 +11,10 @@
#
# ## Changelog
#
# 2023-10-06:
#
# * Speedup in `.rlang_cli_compat()`.
#
# 2022-09-23:
#
# * `format_` functions now use `cli::format_inline()` instead of
Expand Down Expand Up @@ -451,8 +455,12 @@ cli_escape <- function(x) {
is_interactive = return(rlang::is_interactive)
)

# Make sure rlang knows about "x" and "i" bullets
if (utils::packageVersion("rlang") >= "0.4.2") {
ns <- asNamespace("rlang")

# Make sure rlang knows about "x" and "i" bullets.
# Pull from namespace rather than via `utils::packageVersion()`
# to avoid slowdown (#1657)
if (ns[[".__NAMESPACE__."]][["spec"]][["version"]] >= "0.4.2") {
switch(
fn,
abort = return(rlang::abort),
Expand Down

0 comments on commit 7a78dc3

Please sign in to comment.