Skip to content

literal_coercion_linter surfaces coercion warnings #2566

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

Closed
MichaelChirico opened this issue May 3, 2024 · 0 comments · Fixed by #2568
Closed

literal_coercion_linter surfaces coercion warnings #2566

MichaelChirico opened this issue May 3, 2024 · 0 comments · Fixed by #2568
Labels
bug an unexpected problem or unintended behavior

Comments

@MichaelChirico
Copy link
Collaborator

Here we intentionally run as.integer('a') to pull out the coercion warning message to later match against:

https://github.com/Rdatatable/data.table/blob/8c34563c6390d9acb0b4067a9e1d260b57937c24/inst/tests/tests.Rraw#L186

That's fine and can be #nolint'd, but still it throws a warning:

l <- lint(text = 'as.integer("a")', linters = literal_coercion_linter())
# Warning message:
# In eval(expr) : NAs introduced by coercion

The resulting lint message still looks right to me:

<text>:1:1: warning: [literal_coercion_linter] Use NA_integer_ instead of as.integer("a"), i.e., use literals directly where possible, instead of coercion.
as.integer("a")
^~~~~~~~~~~~~~~

So IMO we can solve this by just suppressing warnings in eval() here:

literal_equivalent_str <- vapply(str2expression(coercion_str), function(expr) deparse1(eval(expr)), character(1L))

@MichaelChirico MichaelChirico added the bug an unexpected problem or unintended behavior label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant