Skip to content

literal_coercion_linter surfaces coercion warnings #2566

Closed
@MichaelChirico

Description

@MichaelChirico

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions