Skip to content

ess-eval-region-or-function-or-paragraph-and-step fails to recognize comments between function head and body #1332

Description

@deepayan

This is a minor but long-standing irritant possibly related to #1149. Try loading the following function definitions using C-c C-c:

## This one works fine

foo <- function(x, y, ...) { # This is a comment
    return(x + y)
}

## This one gives an error

bar <- function(x, y, ...) # This is a comment
{
    return(x + y)
}

## Selecting + C-c C-r works

The same behaviour is seen with these variants:

bar <- function(x, y, ...)
### x: first argument
### y: second argument
### ...: ignored
{
    return(x + y)
}

bar <- function(x, y, ...)
    ## x: first argument
    ## y: second argument
    ## ...: ignored
    return(x + y)

The only commonality that I can see that consistently triggers this bug is a comment between the formals and the body, but it also requires the function assignment. Both of the following work:

function(x, y, ...)
    ## This is a comment
{
    return(x + y)
}

(function(x, y, ...)
    ## This is a comment
{
    return(x + y)
})(4, 5)

This is not a showstopper by any means, but perhaps these reproducible examples will make it easier to fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions