Skip to content

assignment_linter with "%<>%" operator causes sprintf error #2850

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

Open
arun-ramamurthy opened this issue Apr 22, 2025 · 1 comment
Open

assignment_linter with "%<>%" operator causes sprintf error #2850

arun-ramamurthy opened this issue Apr 22, 2025 · 1 comment

Comments

@arun-ramamurthy
Copy link

arun-ramamurthy commented Apr 22, 2025

I want to configure my .lintr file to allow for the %<>% operator.

However, using assignment_linter with argument operator containing %<>% is causing strange lintr errors with unrelated lines in my .R files - specifically, it appears to be related to function default arguments as in a = "test" below.

Please see this reprex and the associated error below:

library(lintr)

lines <- c(
  'f <- function(',
  '  a = "test"',
  ') {',
  '}'
)

lint(
  text = lines,
  linters = assignment_linter(operator = c("<-"))
)
#> ℹ No lints found.

lint(
  text = lines,
  linters = assignment_linter(operator = c("%<>%"))
)
#> Error in `lint()`:
#> ! Linter `linter()` failed in '/tmp/RtmpI5xsy4/fileba94779980551':
#> Caused by error in `sprintf()`:
#> ! invalid format '%<>% f'; use format %s for character objects

Created on 2025-04-22 with reprex v2.1.1

@arun-ramamurthy
Copy link
Author

If at all helpful, here is the full trace:

> rlang::last_trace(drop=F)
<error/rlang_error>
Error in `lint()`:
! Linter `linter()` failed in /tmp/Rtmpw4a1aU/fileccc254f7412f8:
Caused by error in `sprintf()`:
! invalid format '%<>% f'; use format %s for character objects
---
Backtrace:
     ▆
  1. ├─lintr::lint(text = lines, linters = assignment_linter(operator = c("%<>%")))
  2. │ ├─base::withCallingHandlers(...) at lintr/R/lint.R:91:9
  3. │ └─lintr:::get_lints(...) at lintr/R/lint.R:91:9
  4. │   ├─lintr:::flatten_lints(linter_fun(expr)) at lintr/R/lint.R:318:5
  5. │   │ └─lintr:::flatten_list(x, class = "lint") at lintr/R/utils.R:18:3
  6. │   │   └─lintr (local) assign_item(x) at lintr/R/utils.R:36:3
  7. │   └─lintr (local) linter_fun(expr) at lintr/R/lint.R:318:5
  8. │     └─base::sprintf(op_lint_message_fmt, op_text) at lintr/R/assignment_linter.R:175:7
  9. └─base::.handleSimpleError(...)
 10.   └─lintr (local) h(simpleError(msg, call))
 11.     └─cli::cli_abort(...) at lintr/R/lint.R:94:13
 12.       └─rlang::abort(...) at cli/R/rlang.R:45:3

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

1 participant