Skip to content

"Rename in Scope" across chunks in R Markdown  #4961

Closed

Description

@dmurdoch

The "Rename in Scope" operation in the Code menu is really handy in R scripts, but not quite as nice in R Markdown documents. It appears to work only within a chunk, whereas the scoping model in R Markdown is that all "r" chunks that are evaluated act like a single script.

For example,

Here I define a variable:
```{r}
bad.var.name <- runif(1)
# [close chunk]
And here I print its value:

```{r}
bad.var.name
# [close chunk]

(where # [close chunk] is supposed to be the three backticks to close the chunk). If I put this in an R Markdown document, then try to Rename in Scope the bad.var.name, only the one in the same chunk gets changed.

Activity

  1. added this to the v1.3 milestone on Jun 17, 2019
  2. ronblum commented on Jun 18, 2019

    @ronblum
    Contributor

    @dmurdoch Thank you for bringing this up! We'll target this for the next major release of RStudio.

  3. removed this from the v1.3 milestone on Dec 2, 2019
  4. domwoolf commented on May 5, 2020

    @domwoolf

    same problem in R scripts when comments separating sections look like chunk headers
    For example:

    #----section_1--------
    rename_this = 1
    print(rename_this)
    
    #----section_2--------
    print(rename_this)
    

    Ends up like this

    #----section_1--------
    newname = 1
    print(newname)
    
    #----section_2--------
    print(rename_this)
    
  5. stale commented on Feb 5, 2021

    @stale

    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.

  6. added
    stale
    on Feb 5, 2021
  7. dmurdoch commented on Feb 5, 2021

    @dmurdoch
    ContributorAuthor

    This is still present in RStudio 1.4.1103.

  8. removed
    stale
    on Feb 5, 2021
  9. danmyles commented on Nov 9, 2021

    @danmyles

    Another option might be to add more options to the Cmd+F menu, for instance: within scope and within chunk?

  10. NewGraphEnvironment commented on Nov 30, 2021

    @NewGraphEnvironment

    Does anyone have any workarounds that they can share to rename in scope over an entire rmd doc?

  11. viktorpm commented on May 29, 2024

    @viktorpm

    Is there any update on this?

  12. added this to the Autumn Crocus milestone on Jun 17, 2024
  13. self-assigned this
    on Sep 26, 2024
  14. ronblum commented on Oct 2, 2024

    @ronblum
    Contributor

    Verified in RStudio Desktop 2024.11.0-daily+258 on Windows 11.

    • Tested in both R Markdown and Quarto.
    • Confirmed for source mode.

    Opened two related issues: #15262 for visual mode, and #15263 for sections in an R script.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions