有没有办法在 RStudio 中禁用环境窗格? [英] Is there any way to disable environment pane in RStudio?

查看:52
本文介绍了有没有办法在 RStudio 中禁用环境窗格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介:

我有一个 RStudio 项目,我正在研究(相当)大数据集.虽然我正在努力保持全球环境清洁,但一段时间后它会变得充满巨大的物体.

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.

问题:

RStudio 在调试后总是刷新环境窗格(可能会迭代全局环境并在每个对象上调用 summary()),并且在我的全局环境上需要几十秒.尽管刷新本身是异步的,但 R 会话很忙,您必须等待它完成才能继续工作.这使得调试非常烦人.而且我不知道在 RStudio 中禁用环境窗格.

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.

问题:

有人可以建议任何漂亮的解决方法吗?我看到以下可能性:

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

  1. 自定义 RStudio 源以添加禁用环境的选项窗格.
  2. 经常清理全局环境(不方便,因为原始数据需要耗时的预处理,而且我经常更改预处理逻辑).
  3. 也许有特定类型的对象会导致延迟,而不是因为它们的大小,而是因为它们的结构?

我现在正在研究可重现的示例,但不清楚是哪些对象导致了问题.

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

我前段时间就该问题通过电子邮件向 RStudio 支持人员发送了电子邮件,但尚未得到任何答复.

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

推荐答案

我可以用很多小的嵌套列表变量重现这个问题.

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

这表明问题在于 RStudio 在全局环境中运行其等效的 ls.str().

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

我怀疑该行为是在 ls("tools:rstudio", all.names = TRUE) 列出的函数之一中实现的,但我不确定是哪个.如果您找到它,您可以覆盖它.

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())

然后在 e 中分配所有结果.这样刷新只需几微秒.

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

这篇关于有没有办法在 RStudio 中禁用环境窗格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆