Skip to content

Editor breakpoints in S7 methods ignored #16490

Closed

Description

@mrcaseb

System details

RStudio Edition : <!-- Desktop or Server --> Desktop
RStudio Version : 2025.09.0+387
OS Version      : macOS Tahoe 26.0, aarch64, darwin20
R Version       : R version 4.5.1 (2025-06-13)
 version  R version 4.5.1 (2025-06-13)
 os       macOS Tahoe 26.0
 system   aarch64, darwin20
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Berlin
 date     2025-09-27
 rstudio  2025.09.0+387 Cucumberleaf Sunflower (desktop)
 pandoc   2.9.2 @ /usr/local/bin/pandoc
 quarto   1.7.33 @ /usr/local/bin/quarto

Steps to reproduce the problem

  • Save the below code lines in a script outside of an R package project
  • Set editor breakpoint in S7 method
  • Save and source the file
  • Run the lines inside the if (FALSE) block. It's in the if block to avoid auto run of the code when the file is sourced.
S7::method(mean, S7::new_class("s7mean")) <- function(x, ...){
  print("This is my S7 method")
}

if (FALSE){
  x <- 1:4
  mean(x)
  
  class(x) <- "s7mean"
  mean(x)
}

Describe the problem in detail

Before Sourcing

Here is how the IDE displays the breakpoint inside the S7 method before sourcing. This looks fine, it tells me to source the file.

Image

After Sourcing

Here is the IDE after I clicked "source". The breakpoint is gone and it's unclear whether it is set or not.

Additionally I see the warning

Breakpoints can only be set inside the body of a function.

which suggests that RStudio doesn't recognize the S7 method as function.

Image

Running the code inside the if block results in

x <- 1:4
mean(x)
#> [1] 2.5

class(x) <- "s7mean"
mean(x)
#> [1] "This is my S7 method"

So the breakpoint wasn't set and the only way for me to solve this is to use browser().

Describe the behavior you expected

I am looking to set editor breakpoints inside S7 methods.

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity

  1. added
    new
    on Sep 27, 2025
  2. added theissue type on Sep 29, 2025
  3. added and removed
    new
    on Sep 29, 2025
  4. gtritchie commented on Sep 29, 2025

    @gtritchie
    Member

    I repro'd this in various releases, so this isn't a recent change in behaviour.

    • 2025.11.0+182
    • 2025.05.2+522
    • 2023.12.1+402
  5. added this to the Globemaster Allium milestone on Sep 29, 2025
  6. self-assigned this
    on Dec 8, 2025
  7. kevinushey commented on Dec 8, 2025

    @kevinushey
    Collaborator

    I spent a bit of time investigating today, and the issue mostly comes down to RStudio not understanding how to resolve the method definition from the code used to define the S7 method.

    We'll need to explore the code here:

    .rs.addFunction("getUntracedFunction", function(
    functionName, fileName, packageName)
    {
    functionName <- .rs.unquote(functionName)
    envir <- .rs.getEnvironmentOfFunction(functionName, fileName, packageName)
    if (is.null(envir))
    {
    return(NULL)
    }
    .rs.untraced(get(functionName, mode = "function", envir = envir))
    })

    and inspect the 'functionName' for things like method(<generic>, <name>), and figure out how to resolve the actual defined function from that call.

    It's a little tricky for us as the code used to retrieve a method, and the code used to define a method, aren't necessarily congruent (re: RConsortium/S7#568).

  8. ronblum commented on Mar 10, 2026

    @ronblum
    Contributor

    Verified using the original example in RStudio Desktop Pro 2026.04.0-daily+364.pro3 on Windows 11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions