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

Accept default= in modify_defaults #1339

Merged
merged 5 commits into from
Jun 2, 2022
Merged

Accept default= in modify_defaults #1339

merged 5 commits into from
Jun 2, 2022

Conversation

MichaelChirico
Copy link
Collaborator

@MichaelChirico MichaelChirico commented Jun 1, 2022

Closes #1336 and closes #1338

Handling it in linters_with_defaults() alone is pretty painful because of the substitute()-based logic for auto-naming, so I implemented the patch inside modify_defaults() instead.

Originally wanted to just throw a warning with modify_defaults() too, but it seems unlikely to use default= by accident there because defaults= is a required argument. So added some uglier logic to allow modify_defaults(default = , ...) to work, assuming that was intentional.

R/with.R Outdated
Comment on lines 38 to 45
warning(
"'default' is not an argument to linters_with_defaults(). Did you mean 'defaults'? ",
"This warning will be removed when with_defaults() is fully deprecated."
)
defaults <- vals$default
vals$default <- NULL
valid_idx <- nms != "default"
nms <- nms[valid_idx]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to use Recall() after the repair to keep the change localized?

Also shouldn't do this if there is also a defaults argument.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we eliminate Recall() as viable for the other similar checks in lint()/lint_package() because of headaches with ...?

Also shouldn't do this if there is also a defaults argument.

OK, actually that will make things a lot easier

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait, I'm not sure that's possible inside modify_defaults. Maybe with running identical(defaults, default_linters). Otherwise need to do the backport inside linters_with_defaults. seems like overkill for something I can't really imagine happening.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would definitely be cleaner to put the warning in linters_with_defaults() though...
Shouldn't something like this work?

dots <- list(...)
if (missing(defaults) && "default" %in% names2(dots)) {
  warning("...")
  names(dots)[names(dots) == "default"] <- "defaults"
  return(do.call(modify_defaults, dots))
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was my first try, but it breaks the substitute(alist(...)) logic in modify_defaults

Copy link
Collaborator

@AshesITR AshesITR Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way? Maybe we can also use substitute(alist(...)) here to generate the correct call?
Possibly even modifying match.call() instead. I'd be fine if the call delegated to a correct invocation of linters_with_defaults() before jumping into modify_defaults().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, seems working now after pulling the naming logic into a helper.

Copy link
Collaborator

@AshesITR AshesITR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks much cleaner now 👍🏻

@AshesITR AshesITR merged commit 83cae10 into main Jun 2, 2022
@AshesITR AshesITR deleted the with-defaults branch June 2, 2022 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants