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

Restore old behavior of @importFrom in some edge cases #1574

Merged
merged 8 commits into from
Jan 19, 2024

Conversation

MichaelChirico
Copy link
Contributor

Closes #1570

@jdblischak
Copy link

This bug also affects #' @importFrom data.table ":=". Might be worth mentioning in the news bullet and adding a test case

R/utils.R Outdated Show resolved Hide resolved
tests/testthat/test-namespace.R Outdated Show resolved Hide resolved
warn_roxy_tag(x, "Excluding unknown {cli::qty(sum(unknown_idx))} export{?s} from {.package {pkg}}: {.code {importing[unknown_idx]}}")
if (all(unknown_idx)) {
return(NULL)
}
x$val <- c(pkg, importing[!unknown_idx])
}
}
Copy link
Member

Choose a reason for hiding this comment

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

One more thought: how do the different types of quoting affect the NAMESPACE? Are they normalised elsewhere, or is it ok to use any of the forms without quoting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean from roxygen2 perspective or base R?

Answering for the latter: NAMESPACE needs to parse as R, so importFrom(magrittr, %>%) won't work.

So for roxygen2, my understanding is @importFrom magrittr %>% will add quotes for convenience (that's the helper auto_quotes), but quoted forms are dropped in as-is.

@hadley
Copy link
Member

hadley commented Jan 16, 2024

@jdblischak do you see something systematically different in that use case to the magrittr example? Or do you think we should just make the news bullet a bit more clear that this applies to any non-syntactic function name?

@jdblischak
Copy link

Or do you think we should just make the news bullet a bit more clear that this applies to any non-syntactic function name?

Exactly. From this PR and the linked Issue, it gives the impression that the edge case is specific to the magrittr pipe.

Also, I just learned that @importFrom dplyr %>% is valid with both roxygen2 7.2.3 and 7.3.0. In the past I've always put non-syntactic function names in quotes. Either I was being overly cautious, or this used to be necessary in older versions. But if using quotes is an edge case, the news bullet could also inform users that the quotes are unnecessary

@MichaelChirico
Copy link
Contributor Author

@jdblischak thanks for the feedback, it's a great point we can use this bullet to remind readers of available convenience features. PTAL if the current bullet gets the point across.

NEWS.md Outdated
@@ -2,6 +2,12 @@

* `@family` lists are now ordered more carefully, "foo1" comes after "foo" (#1563, @krlmlr).

* `@importFrom magrittr "%>%"` works again, as does
``@importFrom rlang `:=` `` (#1570, @MichaelChirico). The form
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd start the bullet with something like `` @importFrom with quoted non-syntactic functions works again, e.g. ...`.

Choose a reason for hiding this comment

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

Agreed. I like the explicit examples, but I think there could be more verbiage to explain what happened. Something like the following:

* `@importFrom` with quoted non-syntactic functions works again, e.g.
  `@importFrom magrittr "%>%"` and ``@importFrom rlang `:=` `` (#1574,
  @MichaelChirico). This was accidentally broken only in 7.3.0 (#1570). The form
  with an unquoted non-syntactic function, e.g. `@importFrom magrittr %>%`,
  has continued to work, even in 7.3.0. Relatedly, `@importFrom` directives not
  matching any known functions (e.g. `@importFrom utils plot pdf`) will not
  produce invalid NAMESPACE files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, PTAL.

tests/testthat/test-namespace.R Outdated Show resolved Hide resolved
Copy link

@jdblischak jdblischak left a comment

Choose a reason for hiding this comment

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

Thanks @MichaelChirico!


import <- expect_no_warning(roc_proc_text(namespace_roclet(), lines))
expect_equal(import, c(
"importFrom(stringr,\"%>%\")",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for my edification, any reason to prefer this to

Suggested change
"importFrom(stringr,\"%>%\")",
'importFrom(stringr,"%>%")',

I like this for keeping the 3 lines of code aligned vertically / no need to visually parse escapes.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have particularly strong feelings here but I like that currently all the strings use ", and are consistent with the values in lines. I saw you used ' for the input "%>%", but I didn't like having to escape #'.

@hadley hadley merged commit a3e3908 into r-lib:main Jan 19, 2024
12 checks passed
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.

Broken support for #' @importFrom with backticks not documented
3 participants