Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning when switch has trailing , #483

Open
hadley opened this issue Jun 22, 2021 · 3 comments
Open

Warning when switch has trailing , #483

hadley opened this issue Jun 22, 2021 · 3 comments

Comments

@hadley
Copy link
Member

hadley commented Jun 22, 2021

Something like:

function(x) {
  switch(x, 1, 2, 3,)
}

Leads to something like:

Error in mapply(FUN = f, ..., SIMPLIFY = FALSE) : 
  (converted from warning) longer argument not a multiple of length of shorter
Backtrace:
     ▆
  1. └─covr::environment_coverage(env, "tests/testthat/test-parse.R")
  2.   └─covr:::trace_environment(env)
  3.     ├─covr:::compact(...)
  4.     └─base::lapply(ls(env, all.names = TRUE), replacement, env = env)
  5.       └─covr:::FUN(X[[i]], ...)
  6.         └─covr:::trace_calls(target_value, name)
  7.           └─covr:::trace_calls(fun_body, parent_functions)
  8.             └─base::Map(trace_calls, x, src_ref, MoreArgs = list(parent_functions = parent_functions))
  9.               └─base::mapply(FUN = f, ..., SIMPLIFY = FALSE)
 10.                 └─(function (x, parent_functions = NULL, parent_ref = NULL) ...
 11.                   └─base::Map(trace_calls, x, src_ref, MoreArgs = list(parent_functions = parent_functions))
 12.                     └─base::mapply(FUN = f, ..., SIMPLIFY = FALSE)
@hadley
Copy link
Member Author

hadley commented Feb 13, 2025

Just saw this again today.

@jimhester
Copy link
Member

The code to handle switch statements in covr is finicky, and this case is not handled well. As this is one of the few (only?) cases that R lets you have trailing empty arguments maybe just avoid doing it as a inconvenient workaround.

@hadley
Copy link
Member Author

hadley commented Feb 18, 2025

Yeah, I'm happy to drop it the trailing comma, I'd just forgotten that's what the root cause of this warning was, so I tracked it down from first principles 😬

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

No branches or pull requests

2 participants