The new version of Rstudio, a few tips for efficient programming

As we all know, RStudio released version 1.0 at the beginning of the month, which aroused the attention and emotion of the majority of users . Many of the major highlights have been known and even tried out.


In addition to the large-scale anti-sky function of notebook, as an IDE, RStudio also has many small details that may not be known to many people. But it is this series of careful thinking that silently improves the work efficiency of the majority of analysts.


This article is to introduce a few of them to you. The full text is translated by Google as usual, and Brother Leopard is not responsible for reviewing it.


1. Detachable panes

Users can split the data pane and code pane from the main interface to reduce frequent switching between panes. Especially if you have more than one monitor, you can drag different panes to different monitor windows to make it look as good as possible. How to use it? Directly press and hold the name of the pane to drag and drop. It is more convenient that there is a small icon under the name of the pane, and you can directly split and restore it by swiping it.




2. History command retrieval

Like many command tools, pressing the up arrow in the R console can call up the command statement that has been used before. Press it once to issue a sentence. If the command is too long, it will really hurt your hand. In fact, as long as you modify it slightly, use Ctrl+↑, you can directly display the list of historical commands, and then select the required statement to execute. More intimately, RStudio will automatically filter out qualified candidate commands based on the starting characters that have been entered in the current console, simplifying the operation steps again.




3. History pane

The history pane shows a list of commands executed in the history (and can be searched). The selected command section can be written directly to the console or code pane. Never copy commands from the console and paste them into code files again.




4. Batch rename

顾名思义,就是同一个变量名在代码的很多位置重复出现,如果写着写着发现需要换个更合适的名字,就不用一个一个去编辑了(也不用Ctrl+F然后再按好多次回车键),而只需要选中需要修改的变量,然后在菜单栏中依次点击Code -> Rename in Scope(默认快捷键是Ctrl+Alt+Shift+M),就可以批量地进行重命名了。这个工具考虑了上下文,因此把变量a1修改为baoge并不会把变量a11误杀为baoge1。




5.notebook里的画廊视图和卫星视图

听起来很神秘?这是当notebook中的代码块产出多幅图形时会使用的展现模式。默认会使用画廊模式(注意不是发廊),即一行缩略图,在缩略图之间切换以查看大图。画廊可以再扩展成一个新的卫星窗口,以便进行更细致的浏览。(这个功能其实挺符合直觉的,感知不大强烈。)




6.代码大纲

如果代码很长,要滚动浏览就会有点花时间了。RStudio针对代码提供了一个大纲视图,适用于notebook的Rmd以及传统的R脚本。在代码窗格菜单栏的最右边按钮点击就可以展开大纲视图(或者使用快捷键Ctrl+Shift+O)。在大纲视图中点击分段标题,就可以导航到相应位置。如果是notebook,Rmd里面的段落标题就定义了大纲的分段;而对于传统的R脚本,则需要用段落注释来定义分段(在菜单栏中依次点击Code -> Insert Section,快捷键是Ctrl+Shift+R)。




7.预设代码块

有些常用代码已经成为了模板,可以利用预设代码块进行快捷的插入(就像预设的短信回复模板一样)。例如,输入fun,按Tab键,就会插入一段用于定义函数的代码框架。此时再按Tab键,还可以依次修改其中的关键元素。RStudio内置的代码模板已经挺多了,当然用户也可以自定义一些个性化的模板。




8.文件导航

大家都知道RStudio里通过Tab键就可以召唤出对函数和参数进行补全的各种选项。其实Tab键还可以帮助列出文件名,咱们就不用手动敲入那些冗长的文件路径了。这个技巧用起来也很自然,在一对双引号中间按下Tab键,就会打开一个简易的文件搜寻下拉框。


动图

9.查看函数的定义

想查看一个函数的内部结构,只要将鼠标点到这个函数上,敲击F2,就会跳转到定义该函数的语句。如果是某个附加包里的函数,则会打开一个新的窗格,展示该函数的定义。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324482697&siteId=291194637