Skip to content

Allow multiline @importFrom, @importClassesFrom, and @importMethodsFrom#1891

Merged
hadley merged 5 commits into
r-lib:mainfrom
kevinushey:fix/importFrom-multiline-1890
Jun 29, 2026
Merged

Allow multiline @importFrom, @importClassesFrom, and @importMethodsFrom#1891
hadley merged 5 commits into
r-lib:mainfrom
kevinushey:fix/importFrom-multiline-1890

Conversation

@kevinushey

Copy link
Copy Markdown
Contributor

Summary

Allow @importFrom, @importClassesFrom, and @importMethodsFrom to span multiple lines, restoring the ability to format imports across multiple lines for readability.

Problem

These tags were incorrectly included in the single-line-only warn_if_multiline() check introduced with tag_words(multiline = FALSE) (#1642, #1688). This caused warnings like:

✖ imports.R:2: @importFrom must be only 1 line long, not 2.
ℹ The first line is "tools"

for perfectly valid multi-line import declarations:

#' @importFrom tools
#'   file_ext md5sum package_dependencies pskill psnice write_PACKAGES

Fix

Pass multiline = TRUE to tag_words() for the three import tag parsers, allowing them to accept multi-line input while still enforcing the min = 2 word requirement.

Changes

  • R/namespace.R: Add multiline = TRUE to tag_words() for @importFrom, @importClassesFrom, and @importMethodsFrom
  • tests/testthat/test-namespace.R: Replace the multiline warning snapshot test with positive tests for all three tags
  • tests/testthat/_snaps/namespace.md: Remove the old snapshot entry
  • NEWS.md: Remove import tags from single-line list; add new bullet for multiline support

Fixes #1890.

…om (r-lib#1890)

These tags now accept multi-line input, restoring the ability to
spread imports across multiple lines for readability. They were
incorrectly included in the single-line-only warning introduced in
the tag_words() multiline check.
@kevinushey kevinushey force-pushed the fix/importFrom-multiline-1890 branch from 7d182ac to d58367d Compare June 25, 2026 21:50
@importFrom, @importClassesFrom, and @importMethodsFrom now use
single-paragraph multiline semantics: a blank line ends the tag, so
content after a forgotten tag (e.g. @examples) is no longer absorbed
into the namespace. Adds a "paragraph" mode to the tag parsers'
multiline argument (r-lib#1890).
Replace the blank-line ('paragraph') terminator for @importFrom,
@importClassesFrom, and @importMethodsFrom with a hanging-indent rule:
continuation lines must be indented more than the first line, and the
first flush or blank line ends the tag. This also handles the case where
a forgotten tag's content is flush rather than separated by a blank line.
The multiline mode is now named 'indent' (r-lib#1890).
Comment thread R/tag-parser.R
#' line is ignored, with a warning. Use this for tags where multiline input
#' is convenient but a blank line almost always signals a missing tag (e.g.,
#' `@importFrom`).
#' * `"indent"`: the tag may span multiple lines, but continuation lines must

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you mind applying https://design.tidyverse.org/boolean-strategies.html#how-do-you-remediate-past-mistakes ? (but without the deprecation; just silently handle TRUE/FALSE since this is mostly an internal API)

@hadley hadley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for continuing to work on this! I'm planning a patch release next week so should be able to get it into the world soon.

Comment thread NEWS.md Outdated
## Individual tags

* Tags that expect single-line input now warn when they span multiple lines, catching a common class of mistake. Affected tags: `@aliases`, `@concept`, `@encoding`, `@exportClass`, `@exportMethod`, `@exportPattern`, `@exportS3Method`, `@importFrom`, `@importClassesFrom`, `@importMethodsFrom`, `@include`, `@includeRmd`, `@inheritDotParams`, `@inheritParams`, `@inheritSection`, `@keywords`, `@method`, `@name`, `@order`, `@rdname`, `@S3method`, `@template`, and `@useDynLib` (#1642, #1688). This may break some existing usage, but it prevents a wide range of otherwise silent errors.
* Tags that expect single-line input now warn when they span multiple lines, catching a common class of mistake. Affected tags: `@aliases`, `@concept`, `@encoding`, `@exportClass`, `@exportMethod`, `@exportPattern`, `@exportS3Method`, `@include`, `@includeRmd`, `@inheritDotParams`, `@inheritParams`, `@inheritSection`, `@keywords`, `@method`, `@name`, `@order`, `@rdname`, `@S3method`, `@template`, and `@useDynLib` (#1642, #1688). This may break some existing usage, but it prevents a wide range of otherwise silent errors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should stay as is; otherwise I think we're good to merge.

@hadley hadley merged commit a3a20ce into r-lib:main Jun 29, 2026
13 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.

importFrom parsing is too strict

2 participants