Is there any way to disable environment pane in RStudio?
Asked Answered
W

2

15

Introduction:

I have an RStudio project where I'm researching (fairly) big data sets. Though I'm trying to keep global environment clean, after some time it becomes filled with huge objects.

Problem:

RStudio always refreshes Environment pane after debugging (probably iterates global environment and calls summary() on each object), and it takes tens of seconds on my global environment. Although the refresh itself is async, R session is busy and you must wait for it to finish before you can continue working. That makes debugging very annoying. And there's no way I know of to disable Environment pane in RStudio.

Question:

Can someone suggest any beautiful workaround of that? I see following possibilities:

  1. Customize RStudio sources to add an option to disable Environment pane.
  2. Frequently clean global environment (not convinient because raw data needs time-consuming preprocessing and I often change preprocessing logic).
  3. Maybe there're specific types of objects that causing the lag not because of their size but because of their structure?

I'm working on reproducible example now, but it's not clear which objects causing the issue.

I've emailed RStudio support about that issue some time ago, but didn't get any answer yet.

Went answered 11/6, 2015 at 6:42 Comment(3)
Please can you add some more detail to reproduce this. How are you doing the debugging? Does it happen when you have a few large objects (the problem is memory, or maybe reading objects), or many small objects (the problem is getting the structure of the objects)? Does it make a difference if the environment pane is hidden (that is, you are looking at the History or Build panes)?Mick
I'm setting breakpoint in RStudio on any line of code, launching the script/function - execution stops on the breakpoint, then I pressing "Stop" or "Continue" button, execution finishes and "refreshing" GIF appears on top of environment pane, during that none of R commands working and RSession.exe process takes 100% of (single core of) CPU. Thus, I don't think it's related to memory. I tried to collapse environment pane, without any effect, I think it refreshes anyway. My environment contains around hundred of objects, some of them a big xts, big lists (of lists), large matrices.Went
Add your support for a disable option here: support.rstudio.com/hc/en-us/community/posts/…Genevivegenevra
M
8

I can reproduce the problem with lots of small nested list variables.

# Populate global environment with lots of nested list variables
invisible(
  replicate(
    1000,
    assign(
      paste0(sample(letters, 10, replace = TRUE), collapse = ""),
      list(a = 1, b = list(ba = 2.1, bb = list(bba = 2.21, bbb = 2.22))),
      envir = globalenv()
    )
  )
)

f <- function() browser()

f() # hit ENTER in the console once you hit the browser

This suggests that the problem is RStudio running its equivalent of ls.str() on the global environment.

I suspect that the behaviour is implemented in one of the functions listed by ls("tools:rstudio", all.names = TRUE), but I'm not sure which. If you find it, you can override it.

Alternatively, your best bet is to rework your code so that you aren't assigning so many variables in the global environment. Wrap most of your code into functions (so most variables only exist for the lifetime of the function call). You can also define a new environment

e <- new.env(parent = globalenv())

Then assign all your results inside e. That way the refresh only takes a few microseconds.

Mick answered 11/6, 2015 at 10:41 Comment(2)
Great, that code reproduces the issue! Notice that environment pane refreshes around 7 seconds (on my i5 4670), but ls works instantly. I think it's clear issue of RStudio. Are 1000 lists of lists can really be considered big global environment? I dug into RStudio sources and no, environment pane doesn't use any functions from tools:rstudio, it calls internal implementation of R's ls inside RSession process through many wrappers, and then iterates the results. So I think the answer is no, there's no way to disable environment pane without changing RStudio code.Went
@Went 1000 variables does sound like a lot. Like I said in the answer, if you are wrapping code in functions, then some of them ought to disappear. And you might be better off with a different data structure. A single list of lists of lists, perhaps.Mick
B
10

While it's not yet available in a public release of RStudio, the v1.3 daily builds of RStudio allow you to disable the automatic-updates of the environment pane:

Environment Pane Popup

Selecting Manual Refresh Only would disable the automatic refresh of the environment pane.

Bedad answered 22/7, 2019 at 4:12 Comment(1)
Thanks! Exactly what I was looking forOnrush
M
8

I can reproduce the problem with lots of small nested list variables.

# Populate global environment with lots of nested list variables
invisible(
  replicate(
    1000,
    assign(
      paste0(sample(letters, 10, replace = TRUE), collapse = ""),
      list(a = 1, b = list(ba = 2.1, bb = list(bba = 2.21, bbb = 2.22))),
      envir = globalenv()
    )
  )
)

f <- function() browser()

f() # hit ENTER in the console once you hit the browser

This suggests that the problem is RStudio running its equivalent of ls.str() on the global environment.

I suspect that the behaviour is implemented in one of the functions listed by ls("tools:rstudio", all.names = TRUE), but I'm not sure which. If you find it, you can override it.

Alternatively, your best bet is to rework your code so that you aren't assigning so many variables in the global environment. Wrap most of your code into functions (so most variables only exist for the lifetime of the function call). You can also define a new environment

e <- new.env(parent = globalenv())

Then assign all your results inside e. That way the refresh only takes a few microseconds.

Mick answered 11/6, 2015 at 10:41 Comment(2)
Great, that code reproduces the issue! Notice that environment pane refreshes around 7 seconds (on my i5 4670), but ls works instantly. I think it's clear issue of RStudio. Are 1000 lists of lists can really be considered big global environment? I dug into RStudio sources and no, environment pane doesn't use any functions from tools:rstudio, it calls internal implementation of R's ls inside RSession process through many wrappers, and then iterates the results. So I think the answer is no, there's no way to disable environment pane without changing RStudio code.Went
@Went 1000 variables does sound like a lot. Like I said in the answer, if you are wrapping code in functions, then some of them ought to disappear. And you might be better off with a different data structure. A single list of lists of lists, perhaps.Mick

© 2022 - 2024 — McMap. All rights reserved.