Skip to content
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

New linter for multiple assignments #2611

Open
MichaelChirico opened this issue Jun 18, 2024 · 0 comments
Open

New linter for multiple assignments #2611

MichaelChirico opened this issue Jun 18, 2024 · 0 comments

Comments

@MichaelChirico
Copy link
Collaborator

It could be nice to catch error-prone behavior in package development like:

my_function <- function(...) { ... }

# lots of code

my_function <- function(...) { ... }

i.e., we define my_function() in multiple places. Then by accident we make a bug fix to the former implementation and scratch our heads why it has no effect on the installed package.

That's the simplest ideal, but there are lots of gotchas here that are potential roadblocks:

  • my_function() might be defined in separate source files (e.g. R/aaa.R, R/bbb.R), and {lintr} currently doesn't maintain any sort of global state like that (and pkgload::load_all() doesn't help since the first definition will simply be overwritten in the package namespace).
  • It would be annoying to be linted for redefining a or b or x or i, simple placeholder variables that might come up several times in an analysis, especially if they're defined in different scopes that don't interact at all anyway.
  • It's perfectly reasonable, though maybe not always the best practice, to write multiple my_function <- ... definitions in different branches of if/else, e.g. to offer a different version of a function in different R (or other upstream package) versions. So we wouldn't want to lint that case.

That said, I think it's possible to come up with something useful & improve it over time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant