Skip to content

nonportable_path_linter lints gsub("[^0-9\\-]", "", x) #2949

@mcol

Description

@mcol

This shows the problem:

lintr::lint(text = 'gsub("[^0-9\\\\-]", "", x)', linter = lintr::nonportable_path_linter())
# <text>:1:7: warning: [nonportable_path_linter] Use file.path() to construct portable file paths.
# gsub("[^0-9\\-]", "", x)
#       ^~~~~~~~~

A minimized version:

lintr::lint(text = "'[\\\\-]'", linter = lintr::nonportable_path_linter())
# <text>:1:2: warning: [nonportable_path_linter] Use file.path() to construct portable file paths.
# '[\\-]'
#  ^~~~~

Actually, my script has gsub("[^0-9\\-]", "", x), but this is parsed differently when using text:

lintr::lint(text = "gsub('[^0-9\\-]', '', x)", linter = lintr::nonportable_path_linter())
# <text>:1:13: error: [error] '\-' is an unrecognized escape in character string.
# gsub('[^0-9\-]', '', x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    false-positivecode that shouldn't lint, but does

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions