以编程方式关闭 RStudio 中的数据查看器选项卡
我想制作一个脚本来关闭 RStudio 中的所有数据查看器选项卡(通过单击“环境”窗格中的数据对象或通过调用 utils::View() 来调用这些选项卡),但保留所有“通常的”文档选项卡。
首先,我发现 rstudioapi::documentClose() 函数 - 不确定它是否适用于数据查看器选项卡,它需要的文档 ID 似乎不适用于此处:调用 getActiveDocumentContext()<数据查看器选项卡上的 /code> 返回
#console
。
然后,有 executeCommand('closeSourceDoc')
选项用于关闭当前选项卡,无论是数据查看器还是标准文档。我可能可以使用 executeCommand('nextTab')
循环遍历所有打开的选项卡,但我找不到如何确定活动选项卡是否是数据查看器...
有什么提示吗?
I wanted to make a script that closes all Data Viewer tabs in RStudio (those invoked by clicking on a data object in the Environment pane, or by calling utils::View()
) but keeps all the "usual" document tabs.
First, I found rstudioapi::documentClose()
function - not sure if it works for Data Viewer tabs, it requires the document id that seems to be not applicable here: calling getActiveDocumentContext()
on Data Viewer tab returns #console
.
Then, there's executeCommand('closeSourceDoc')
option that closes the current tab, whether it is Data Viewer or standard document. I could probably use executeCommand('nextTab')
to loop through all opened tabs, but I can't find how to determine if the active tab is Data Viewer or not...
Any hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的代码似乎可以满足您的要求。
The following code seems to do what you want.