Why does lintr think structure() is an undesirable function?

lintr is throwing errors related to undesirable_function_linter:

image

Can someone tell me why the structure() function is considered undesirable? Is it on the road to deprecation?

Thanks.

2 Likes

The PR that added to lintr provides a bit more context and discussion: avoid structure() by MichaelChirico · Pull Request #2227 · r-lib/lintr · GitHub

1 Like

@maelle Thank you! That explains it.

1 Like

I agree with @klmr's opinion that this seems overly subjective for a default behavior.

Also,@ESimms what version of {lintr} are you using? I use structure() in one of my packages, but I don't get any lint about it. I tried both 3.1.1 and the latest 3.1.1.9000 from GitHub. Here's a reprex:

packageVersion("lintr")
## [1] ‘3.1.1.9000’
x <- tempfile()
writeLines("structure(list(x = 1))", x)
lintr::lint(x)

Am I using {lintr} wrong?

2 Likes

3.1.1

In our .lintr file, we are asking for the undesirable_function_lintr to be used:

linters: linters_with_defaults(
    line_length_linter(100),
    object_usage_linter=NULL,
    cyclocomp_linter(complexity_limit = 22),
    indentation_linter=NULL,
    undesirable_function_linter = undesirable_function_linter()
  )
exclusions: list(
    "R/data.R" = Inf,
    "inst" = list(undesirable_function_linter = Inf),
    "vignettes" = list(undesirable_function_linter = Inf),
    "R/admiral_options.R" = list(line_length_linter = 8)
  )

The indentation_linter is turned off, for now, because we have a discrepancy between styler and lintr; that is my next task to figure out: how to align lintr with styler.

2 Likes

Ah, thanks for the explanation. Now I understand. structure() is flagged by default, but only if you opt-in to the undesriable_function_linter().

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.