Skip to content

reprex_alert() errors with its default type argument - #675

Open
sims1253 wants to merge 1 commit into
tidyverse:mainfrom
sims1253:fix/ry-audit-findings
Open

reprex_alert() errors with its default type argument#675
sims1253 wants to merge 1 commit into
tidyverse:mainfrom
sims1253:fix/ry-audit-findings

Conversation

@sims1253

@sims1253 sims1253 commented Aug 1, 2026

Copy link
Copy Markdown

Found this during my most recent ry audit

Summary

The internal reprex_alert() helper errors at runtime whenever it is called
with its declared default type argument, because the default is passed
straight to switch() without first reducing it to a scalar.

Reproducible example

pkgload::load_all()
local_reprex_loud()  # or run outside of testing
reprex:::reprex_alert("hello")
#> Error in switch(type, success = cli::cli_alert_success, info = cli::cli_alert_info,  :
#>   EXPR must be a length 1 vector

Root cause

reprex_alert() declares the match.arg()-style default but never calls
match.arg():

reprex_alert <- function(
  text,
  type = c("success", "info", "warning", "danger"),
  .envir = parent.frame()
) {
  quiet <- reprex_quiet() %|% is_testing()
  if (quiet) {
    return(invisible())
  }
  cli_fun <- switch(           # <-- `type` is length 4 here
    type,
    success = cli::cli_alert_success,
    ...
  )
}

With the default, type is the length-4 character vector
c("success", "info", "warning", "danger"), and switch() requires a
length-1 EXPR, so it errors with EXPR must be a length 1 vector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant