Skip to content

Code > Reflow Comment (Ctrl/Cmd+Shift+/) does not work well with @examplesIf #14327

Open

Description

@asadow

It combines lines incorrectly and adds unnecessary indentation:

#' @examplesIf megamation:::has_creds()
#' date <- seq.Date(as.Date("2023-01-01"), as.Date("2023-01-02"), by = "day")
#' mm_dl("timecard", date = date)

Becomes

#' @examplesIf megamation:::has_creds() date <- seq.Date(as.Date("2023-01-01"),
#'   as.Date("2023-01-02"), by = "day") mm_dl("timecard", date = date)

Activity

  1. added
    new
    on Feb 26, 2024
  2. ronblum commented on Feb 27, 2024

    @ronblum
    Contributor

    @asadow Thank you for raising this!

    Confirmed even going back to RStudio Desktop 2022.7.2.576 on MacOS 14.4.


    While we're at it, here's what occurs with something plainer. For example,

    #' 1
    #' 2
    #' @c 
    #' @d <- 4
    #' 5 A very long line that's longer than the width of a page and should therefore wrap aroud to the next line
    #' 6
    

    becomes

    #' 1 #' 2 #' @c #' @d <- 4 #' 5 A very long line that's longer than the width of
    a page and should therefore wrap aroud to the next line #' 6
    

    This isn't just with roxygen comments, though. The behavior is the same with regular comments:

    # 1
    # 2
    # @c 
    # @d <- 4
    # 5 A very long line that's longer than the width of a page and should therefore wrap aroud to the next line
    # 6
    

    becomes

    # 1 # 2 # @c # @d <- 4 # 5 A very long line that's longer than the width of a
    page and should therefore wrap aroud to the next line # 6
    
  3. added and removed
    new
    on Feb 27, 2024
  4. github-actions commented on Aug 26, 2024

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.

  5. added
    stale
    on Aug 26, 2024
  6. olivroy commented on Aug 26, 2024

    @olivroy
    Contributor

    Still an issue! I really like the Reflow Comments feature as there are no other efficient way to wrap roxygen comments to 80 character. There are no good alternatives. (styler ignores them for example r-lib/styler#1147) but unfortunately, this bug makes it harder to use.

    Maybe if @examplesIf were interpreted like @examples, it would work correctly?

    I am not entirely sure what these lines do, but updating the regexp to allow two extra characters would possibly help?

    This regex appears correct

    public static Pattern PATTERN_ROXYGEN_EXAMPLES_LINE = Pattern.create("^\\s*#+'\\s*@examples", "");

    This currently would match #' @example and #' @examples, but not #' @examplesIf.

  7. removed
    stale
    on Aug 26, 2024
  8. added this to the Mariposa Orchid milestone on Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions