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

Special case imports code to run first #1538

Merged
merged 10 commits into from
Nov 21, 2023
Merged

Special case imports code to run first #1538

merged 10 commits into from
Nov 21, 2023

Conversation

hadley
Copy link
Member

@hadley hadley commented Nov 17, 2023

Fixes #1144

@hadley hadley merged commit 1ea43c9 into main Nov 21, 2023
12 checks passed
@hadley hadley deleted the namespace-first branch November 21, 2023 17:50

update_namespace_imports <- function(base_path) {
NAMESPACE <- file.path(base_path, "NAMESPACE")
if (!made_by_roxygen(NAMESPACE) || !file.exists(NAMESPACE)) {
Copy link
Contributor

@MichaelChirico MichaelChirico Nov 21, 2023

Choose a reason for hiding this comment

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

It seems odd to run file.exists() twice (first by made_by_roxygen(), then again directly here)

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't the logic opposite? We treat a missing NAMESPACE as made by roxygen2 so we can override it. Or are you just suggesting I flip the order of the conditional?

Copy link
Contributor

@MichaelChirico MichaelChirico Nov 21, 2023

Choose a reason for hiding this comment

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

I'm a bit torn... from readability, it makes more sense to me like (1) check file exists (2) check if it's made by roxygen, but in implementation IINM that would mean file.exists() is always run twice, whereas the current, reverse ordering means it may only be run once.

file.exists() is of course not very expensive on most file systems so this is not v. important, sorry for the fly-by comment :)

Copy link
Member Author

Choose a reason for hiding this comment

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

No problem; I had to think this through too when I wrote it, which is probably a sign it needs some refactoring, but it doesn't quite hit the threshold to be worth it.

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

Successfully merging this pull request may close these issues.

devtools::document() errors before NAMESPACE can be updated
2 participants