Skip to content

debugSource() throws a warning when getOption("keep.source") is FALSE #12375

Closed

Description

@ArcadeAntics

debugSource() throws a warning when options(keep.source = FALSE):

> debugSource(this.path())

> LINENO()
[1] NA
Warning message:
In structure(c(refs[[1]][1], refs[[1]][2], refs[[lastref]][3], refs[[lastref]][[4]],  :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
> 

I think this is easily fixed in .rs.makeSourceEquivFunction(), right after refs <- attr(content, "srcref"), by adding something like:

    if (is.null(srcref))
        return(fun)

I'm not sure if this has any further implications for other functions in RStudio, but I'd imagine something similar could be added to those as well. Thank you!

Activity

  1. kevinushey commented on Jan 9, 2023

    @kevinushey
    Collaborator

    Thanks for the bug report. To confirm, here's a small reproducible example:

    options(keep.source = FALSE)
    rfile <- tempfile(fileext = ".R")
    writeLines("print('Hello, world!')", con = rfile)
    debugSource(rfile)
    

    When executed, I see:

    > options(keep.source = FALSE)
    > rfile <- tempfile(fileext = ".R")
    > writeLines("print('Hello, world!')", con = rfile)
    > debugSource(rfile)
    Warning in structure(c(refs[[1]][1], refs[[1]][2], refs[[lastref]][3], refs[[lastref]][[4]],  :
      Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
      Consider 'structure(list(), *)' instead.
    [1] "Hello, world!"
    

    Internal note: options(keep.source = FALSE) is not the default, but might be set by R users in order to save a bit of extra memory in the R session (at the cost of losing source references, IIUC)

  2. added this to the Backlog-2 milestone on Jan 9, 2023
  3. modified the milestones: Backlog-2, Later on Oct 5, 2023
  4. AzazelSensei commented on Aug 29, 2026

    @AzazelSensei

    Opened #18686. makeSourceEquivFunction now returns before wiring srcrefs when parse() leaves them NULL.

  5. added theissue type on Aug 30, 2026
  6. self-assigned this
    on Oct 26, 2026
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